css - :nth-child(n)选择器中的n可不可以引用到属性中?
PHP中文网
PHP中文网 2017-04-17 11:09:25
0
2
716

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

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

认证高级PHP讲师

reply all(2)
黄舟

On a native basis, some Firefox browsers can implement CSS variables

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

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

See MDN’s documentation for details https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_variables

刘奇

No
n in nth-child(n) can be in the form of an b, or odd, even or number, so it should not be used as a variable
The effect you want to achieve should be achieved using js
Or you can use some css preprocessing language that supports variables

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template