My Twitter

Making Zebra Stripes with CSS3

October 30th, 2009

Zebra Stripping is the technique of having different colours per each line on a list. It generally is considered to help users read large tables of information; however there is evidence suggesting the effectiveness of zebra stripes is somewhat overrated. Having said that, in CSS3 it’s very easy to implement so it’s worthwhile adding.

To add Zebra Strips to a list, all you need to do is adding the following pseudo-class to the end of the CSS element you wish to edit:

ul#example_list li:nth-child(odd) {
 background-color:#FFF;
}

In this example, I’ve used an unordered list element. The data in the brackets refers to the “nth” number to affect, for example putting “(even)” will affect every even <li>. You can also put number in, for example “(3)” would affect every 3rd <li>.

Below is a link to a working example of the code in action (Feel free to copy & share).

zebra_strips_in_css3

If you want to read a bit more about the nth-child pseudo-class I recommend the sitepoint CSS reference.

Tags: , , , , , , , , , , , , , , ,

DeliciousFacebookDigg
TwitterStumbleUponGoogleLinkedInRSS Feed

Leave a Reply

Comment moderation is enabled. Your comment may take some time to appear.

3 Responses to “Making Zebra Stripes with CSS3”

  1. Just posted: Making Zebra Stripes with CSS3 – http://bit.ly/1lDyUj

  2. Great Icons ;)
    Lovey tut, Just what I needed.

  3. Mike replied:

    Glad you found it useful :)