Is it possible to use the nth-child value as a parameter in a property? (and how)

前端 未结 2 873
野的像风
野的像风 2020-12-15 10:46

Short description (tl;dr;)

Is there a \"pure CSS\" way (not Less/Sass) of using the value of the nth-child inside the CSS properties? Something like t

2条回答
  •  孤城傲影
    2020-12-15 10:59

    CSS variables have almost universal support on all modern browsers and can achieve virtually the same desired effect as @GreatBlake's answer using attr plus more. Instead of defining data in a user-defined attribute, you can define it as a custom property in the style attribute and get the value of those custom properties using the var() function:

    
    
    
    
    
    
    span.anim {
      animation-delay: calc(var(--n) * 0.5s);
    }
    

提交回复
热议问题