CSS Alternate Rows

Creating Different-Looking Rows with CSS

We can use this method if we want one row of the lists that we prepared using Table or ol - ul to look different and the other row to look different. It is very simple to use and what is done is to create a different style for odd numbered (odd) lines and a different style for even numbered lines.

Sample:

To create a list (ul tag) like above, we can write the following css codes:

li:nth-child(odd) { background-color:#eee; }

li:nth-child(even) { background-color:#fff; }

If we want to do the same thing for a table;

tr:nth-child(odd)  { background-color:#eee; }

tr:nth-child(even) { background-color:#fff; }

 

creating alternate rows css, making each row of the table different, table odd even rows different format, list odd even rows different format

EXERCISES

Alternate Table Rows With CSS Try It

tr:nth-child(odd) { background-color:#eee; } /* odd numbered rows */

tr:nth-child(even) { background-color:#fff; } /* even numbered rows */

Alternate List Items of Ul Try It

li:nth-child(odd) { background-color:#eee; } /* odd numbered list items */

li:nth-child(even) { background-color:#fff; } /* even numbered list items */



COMMENTS




Read 827 times.

Online Users: 194



css-odd-even-rules