Code Snippet

Home » Code Snippets » CSS » CSS3 Zebra Striping a Table

CSS3 Zebra Striping a Table

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

Subscribe to The Thread

  1. great certainly saved me some time searching

  2. this didn’t work well for me, but the PHP one worked great.

    • CSS3 zebra striping is better solution! Why? Here is the right concept:

      1. PHP generates html as output, which should not care how the elements looks like.
      2. CSS purpose is to “care” how the elements looks like.

  3. Cant understand, how it works…

  4. @Dyllon and @Artem, here is a simple demo explaining how to use this code, and a live example of it being used.

    http://webdesignandsuch.com/2010/08/add-zebra-striping-to-a-table-with-css3/

  5. Sadly… not supported by IE

  6. Can be done with jQuery addClass.

  7. Maksvil

    shitty explorer not supported

  8. I bet these people saying that it isn’t working are browsers that are not supported. :D

  9. Just wanted to say thanks for all of the cool tips and tricks. I’ve used the css zebra stripe trick before but it hadn’t occurred to me to prefix my css with tbody so that I could better target hovers and such.

  10. How do you maintain a consistent zebra pattern in a sortable PHP table?

  11. This is awesome, sadly it’s not working in IE. Therefore I am using the PHP or jQuery way, until IE wakes up and shuts down that terrible browser.

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~