CSS nth-child apply odd-even rule but switch every 4 items

后端 未结 3 1602
南旧
南旧 2020-12-19 20:42

I have a list of divs that appear 4 in a row with a class and I would like to create a checkerboard background style, meaning:

  • Apply a different
3条回答
  •  爱一瞬间的悲伤
    2020-12-19 21:29

    Just after the solution from @Miszy, I also found a jQuery solution that does the same thing regardless of how many divs will appear on the page:

    $(document).ready(function() {
        $(.boxwrapper:nth-child(8n+3), .boxwrapper:nth-child(8n+5), .boxwrapper:nth-child(8n+8), .boxwrapper:nth-child(8n+10)").css({"background-color":"red"});
    });
    

    Either one will work fine.

提交回复
热议问题