Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to switch the colors of the rows in a table/grid?

How to switch the colors of the rows in a table/grid?

Problem

Is there any way to switch the colors of the rows in a table/grid in CSS or CSS3?

Name Votes
Barack Obama 50%
Mitt Romney 48%

Where for example, odd rows are white and even rows are blue.

.rows tr:odd
{
    background-color: White
}
.rows tr:even
{
    background-color: blue
}

Or is that not possible?

Problem courtesy of: JuninZe

Solution

You can use the nth-child selector to achieve this:

.rows tr:nth-child(even) {background-color: #fff}
.rows tr:nth-child(odd) {background-color: blue}
Solution courtesy of: Justin Helgerson

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

How to switch the colors of the rows in a table/grid?

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×