我有一个列表 ul>li*5 (不总是相同的数量)。我设置了一个计数器,我得到了:
1 2 3 4 5
li:nth-child(n):before {
counter-increment: skill;
content: counter(skill);
color: white;
}
问题 我可以在 calc() 中使用 计数器(技能) 还是可以向它添加单位 px em rem % ms s
我试过了:
transition: all 250ms linear #{counter(skill)} * 1s;
transition: all 250ms linear counter(skill) * 1s;
我想增加延迟,例如:
li 1s delay
li 2s delay
li 3s delay
li 4s delay
li Xs delay
原文由 T04435 发布,翻译遵循 CC BY-SA 4.0 许可协议
不,你不能。
calc
函数不允许使用counter
函数作为其组件。从这里的规范 - https://www.w3.org/TR/css3-values/#calc-notation :对此有很多要求,但总是被拒绝。根本原因似乎是
counter()
函数表示(输出)一个<string>
因此不能直接用于calc
。此外,计数器被认为对浏览器来说非常昂贵。参考: https ://lists.w3.org/Archives/Public/www-style/2016Aug/0082.html
但是,有人建议添加一个
counter-value()
函数,该函数将返回整数值并可用于calc
。请参阅此处: https ://drafts.csswg.org/css-lists-3/#counter-functions(向下滚动以查看第 4 期)。因此,截至目前,您不能在
counter
calc
并且counter-value
尚不存在。