CSS nth-child ignores the first 3 elements, stylize the other 3 and repeats. Possible?

前端 未结 2 1058
执笔经年
执笔经年 2021-01-26 23:27

I know that nth-child is for every nth element, but maybe it\'s possible to ignore the first 3 elements, stylize the other 3 and repeat for a huge list. I tried to write that ev

相关标签:
2条回答
  • 2021-01-27 00:05

    You can use:

    :nth-child(6n+4), :nth-child(6n+5), :nth-child(6n+6) {
        CSS RULES
    }
    

    For example: http://jsfiddle.net/BYossarian/3HwU9/2/

    The multiplier for n will be the length of your repeating pattern (in this case 6 because you have 3 off, and then 3 on), and then you add/subtract a number to pick out the right elements within the pattern (in this case, the 4th, 5th and 6th elements of the pattern).

    0 讨论(0)
  • 2021-01-27 00:18

    http://jsfiddle.net/bhlaird/7c3aw/ If you want your pattern to repeat every 6 elements (3 on, 3 off) use 6n.

    div:nth-child(6n+4), div:nth-child(6n+5), div:nth-child(6n+6) {
        background-color:#0066cc;
    }
    
    0 讨论(0)
提交回复
热议问题