nth-Child CSS selectors

后端 未结 2 1893
遥遥无期
遥遥无期 2020-12-10 21:13

I have nine sets of color schemes that I want to apply to a sequence of divs. Using :nth-child(1), :nth-child(2)... works for the first nine, but I\'d like the

2条回答
  •  臣服心动
    2020-12-10 21:34

    If you mean you need to apply different rules to every nine consecutive elements, you have to use these nine selectors:

    :nth-child(9n+1)
    :nth-child(9n+2)
    :nth-child(9n+3)
    :nth-child(9n+4)
    :nth-child(9n+5)
    :nth-child(9n+6)
    :nth-child(9n+7)
    :nth-child(9n+8)
    :nth-child(9n+9) /* Or :nth-child(9n) */
    

提交回复
热议问题