首页 > :nth-child(n)选择器中的n可不可以引用到属性中?

:nth-child(n)选择器中的n可不可以引用到属性中?

如果是原生的CSS(不使用编译器)可不可以达到这样的效果?
或者有没有哪个属性或方法是可以使数值与n相关的?

.box:nth-child(n){
    -webkit-animation-delay:n s;
            animation-delay:n s;
}

在原生的基础上,部分 Firefox 浏览器可以实现 CSS 变量

element {
  --animation-delay: 3s;
} 

.box:nth-child(n) {
-webkit-animation-delay: var(--animation-delay);
        animation-delay: var(--animation-delay);
}

详情看 MDN 的文档 https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables


不行
nth-child(n) 中的n可以是an+b形式,或odd,even或数字,所以不应该被作为变量使用
你要实现的效果应该用js实现
或者可以使用一些支持变量的css预处理语言

【热门文章】
【热门文章】