CSS div alternating colour

前端 未结 3 1693
醉话见心
醉话见心 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:51

    Don't use nth-child, use nth-of-type

    div.container > div:nth-of-type(odd) {
        background: #e0e0e0;
    }
    

    .container {
      width: 600px;
      margin: 0 auto;
    }
    
    .row {
      line-height: 24pt;
      border: solid 1px black;
    }
    
    div.container>div:nth-of-type(odd) {
      background: #e0e0e0;
    }
    
    h3 {
      line-height: 36pt;
      font-weight: bold;
      color: blue;
    }

    Title

    Content
    Content
    Content
    Content

    Title

    Content
    Content

    Title

    Content
    Content
    Content
    Content
    Content

    Title

    Content
    Content
    Content
    Content

提交回复
热议问题