Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create zebra stripes on html table without using javascript and even/odd classes generation?

Tags:

css

html-table

I want to zebra-stripe a html table without using any js stuff or writing server-side code to generate even/odd classes for table rows. Is it ever possible to do using raw css?

like image 717
Vladimir Avatar asked May 04 '10 13:05

Vladimir


People also ask

How do you make a striped table?

This article will tell you how to create a zebra-stripped table (rows or columns) in a webpage by using HTML and CSS only. Table with Zebra Stripped rows: Tap into the tr (table row) element is CSS. Use the nth-child() selector and add background-color of your choice to all odd (or even) table rows.

How do you make a zebra stripe in CSS?

Using :nth-of-type(n) with tables One of the most common ways to style tables is to set the background color of every other row. This is often referred to as "zebra stripes." You can accomplish this by setting every other row with a CSS class and then defining the style for that class.


1 Answers

It is possible, with CSS3 selectors:

tr:nth-child(even) {   background-color: red; }   tr:nth-child(odd) {   background-color: white; } 

According to caniuse.com, every browser supports it now.

like image 76
K. Norbert Avatar answered Sep 28 '22 21:09

K. Norbert