我想在calc()
函数中使用inherit
,像这样:
#foo {
animation-duration: 10s;
}
#foo > .bar {
animation-duration: calc(inherit + 2s); /* =12s */
}
但它似乎无效。
这是浏览器的错误还是规范的问题?
我想在calc()
函数中使用inherit
,像这样:
#foo {
animation-duration: 10s;
}
#foo > .bar {
animation-duration: calc(inherit + 2s); /* =12s */
}
但它似乎无效。
这是浏览器的错误还是规范的问题?
inherit
关键字只能作为属性声明中的值单独存在,不能与其他任何内容一起使用,因为它是一个独立的值。这意味着它也不能与像calc()
这样的函数一起使用。请参见CSS2.1和css3-cascade。
简而言之,规范不允许以那种方式使用inherit
。
考虑到这一点,为了将继承的属性值用作子声明的一部分,请创建一个将继承的自定义属性:
#foo {
--duration: 10s;
animation-duration: var(--duration);
}
#foo > .bar {
/* --duration is automatically inherited - no need for inherit keyword */
animation-duration: calc(var(--duration) + 2s); /* =12s */
}
calc(100% + 2s)
,因为持续时间属性不接受百分比。(仅仅120%
也不行。)很抱歉。不过这是个好问题! - Mr Lister@duration:10s; #foo {animation-duration:@duration;} #foo > .bar {animation-duration:@duration + 2s; }
。当然,那并不完全相同。还有CSS变量,但那现在还只是科幻。 - Kobi