AKalair Posted February 20, 2009 Share Posted February 20, 2009 Hello, How can I use CSS to have alternating colours for the background of a table. For instance the first row is black, the next white and so on. Thank You Quote Link to comment https://forums.phpfreaks.com/topic/146089-alternating-table-colours-in-css/ Share on other sites More sharing options...
haku Posted February 20, 2009 Share Posted February 20, 2009 .black { background-color:black; } .white { background-color:white; } <tr class='black'> // stuff in row </tr> <tr class='white'> // stuff in row </tr> <tr class='black'> // stuff in row </tr> etc. Quote Link to comment https://forums.phpfreaks.com/topic/146089-alternating-table-colours-in-css/#findComment-766939 Share on other sites More sharing options...
TheFilmGod Posted February 21, 2009 Share Posted February 21, 2009 CSS3 method: tr:nth-child(odd) { background-color:#eee; } tr:nth-child(even) { background-color:#fff; } Quote Link to comment https://forums.phpfreaks.com/topic/146089-alternating-table-colours-in-css/#findComment-767562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.