CSS div alternating colour

前端 未结 3 1704
醉话见心
醉话见心 2020-12-13 08:12

I\'m trying to zebra stripe my divs in my website, sounds simple enough, however I\'ve found that when I added a header in between the rows of my divs it seems to count the

3条回答
  •  忘掉有多难
    2020-12-13 08:34

    The easiest solution is of course just to wrap the elements you want striped.

    Your updated jsFiddle.

    HTML

    Title

    Content
    Content

    Title

    Content
    Content
    Content

    Title

    Content
    Content
    Content
    Content

    CSS

    .row:nth-child(odd) {background: #e0e0e0;}
    

    Bear in mind also that if browser support is important to you, you might want to generate additional classes for zebra-striping server side instead.

提交回复
热议问题