CSS refer to every odd nested child?

前端 未结 3 945
傲寒
傲寒 2021-01-14 09:21

I\'m trying to make a comment system where nested comments have zebra background colors. (Blue bg replies to white bg replies to blue bg...)

Instead of referring to

相关标签:
3条回答
  • 2021-01-14 09:58

    I have a system where I wanted the Zebra effect on all the Rows in a table, i used the following jQuery. Maby the selector will apply for you as well.

    $('#celebs tbody tr:even').css('background-color','#ffffdffffd');
    

    Hope this helps

    0 讨论(0)
  • 2021-01-14 09:58

    Look for nth-child in the CSS reference, selectors section. It's used something like this:

    tr:nth-child(even) {
       background: #cccccc;
    }
    tr:nth-child(odd) {
       background: white;
    }
    

    you don't have to apply different classes to alternating rows; CSS itself will distinguish even rows from odd rows.

    0 讨论(0)
  • 2021-01-14 10:19

    You could add an alternating class to accompany .comment that's applied procedurally as the comments are being laid out on the page (e.g: .row1, .row2, etc.) and then style those classes accordingly with CSS.

    0 讨论(0)
提交回复
热议问题