Style every third element?

前端 未结 8 1625
小蘑菇
小蘑菇 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:47

    section > div:nth-child(3n+1) {
        background:red;
    }
    

    This style is good for fixing your problem, but '>' this symbol, isn't supported for old browsers, for example: IE5, IE6, IE7 . . .

    But I prefer this way, without '>' symbol

    section div:nth-child(3n+1) {
        background:red;
    }
    

提交回复
热议问题