Conditional alternative table row styles in HTML5
Is there any changes regarding this questions Conditional alternative table row styles since HTML5 came in?
Here is a copy of original question:
Is it possible to style alternate table rows without defining classes on alternate tags?
With the following table, can CSS define alternate row styles WITHOUT having to give the alternate rows the class "row1/row2"? row1 can be default, so row2 is the issue.
<style>
.altTable td { }
.altTable .row2 td { background-color: #EEE; }
</style>
<table class="altTable">
<thead><tr><td></td></tr></thead>
<tbody>
<tr><td></td></tr>
<tr class="row2"><td></td></tr>
<tr><td></td></tr开发者_JAVA百科>
<tr class="row2"><td></td></tr>
</tbody>
</table>
CSS3 supports the "nth-child" property on the tr tag. Something like the following should work:
tr:nth-child(odd) { background-color: white; }
tr:nth-child(even) { background-color: green; }
Jacob R's solution to your original posting still applies.
精彩评论