1

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>
    <tr class="row2"><td></td></tr>
   </tbody>
  </table>

2 Answers 2

5

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; }
Sign up to request clarification or add additional context in comments.

Comments

0

Jacob R's solution to your original posting still applies.

2 Comments

But author told: "Does not work in IE"..? Do you mean it is ok?
It still doesn't work in IE, sadly. For IE, you will have to continue with the alternating classes or use JS to add the striping in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.