Style every third element?

前端 未结 8 1636
小蘑菇
小蘑菇 2020-12-15 05:11

How can I style every third element with plain CSS.

I have seen questions like this, but they involve javascript. I want a plain CSS solution. I know I can use

8条回答
  •  不知归路
    2020-12-15 05:35

    Possible solution is

    section div:nth-child(3n+1) {  
        color: #ccc;
    }
    

    The above code styles every 3rd element starting from first element as requested.
    Change the number after '+ sign' to set the starting element.
    Change the number before n charecter to set the elements after to be styled

提交回复
热议问题