dtsn · I build cool stuff for the web. Hi I'm Daniel and I blog about design, JavaScript and CSS. Find out more about me and subscribe to my feed.

Archive for the ‘CSS3’ Category

Styling Odd and Even Elements in CSS

A part of CSS3 are a fantastic new range of selectors, these include the ;nth-child sudo class. These allow you to style the nth child of a parent element. Therefore you can easily style the odd:

tr:nth-child(odd)

or even elements:

tr:nth-child(even)

For example this is my table where I have styled each even row:

Example Data 1 Example Data 2
Example Data 3 Example Data 4
Example Data 5 Example Data 6
Example Data 7 Example Data 8

You can find more information on this on the W3C CSS3 Selectors page.