Search code examples
csscss-tables

Alternate row color


I want to display alternate rows in different color. I have specified the color in CSS. And most of the rows are working properly.When I checked, rows are having either class="odd" or class="even" but some rows are having class="odd even" and class="even odd". How it is happening ? Could anyone explain why it is taking the class as "odd even" or "even odd". Thanks in advance.

table.dataTable .odd { background-color:  red; }
table.dataTable .even { background-color: green;  }

Solution

  • Why are you even using classes for this?

    tr {background-color:white}
    tr:nth-child(even) {background-color:black}