What is the best way to style alternating rows in a table?

后端 未结 12 550
南方客
南方客 2020-12-11 11:09

Obviously, the actual style of the odd/even rows will be done via a CSS class, but what is the best way to \"attach\" the class to the rows? Is is better to put it in the ma

12条回答
  •  长情又很酷
    2020-12-11 11:42

    What you're trying to accomplished can even be done with CSS3:

    tr:nth-child(odd) { background: #FFF; }
    tr:nth-child(even) { background: #AAA; }
    

    This is also listed in the w3's css3 selectors spec. If you're looking for compatibility, adding the class server-side or through javascript would be a far better solution.

提交回复
热议问题