A HTML table can be difficult to read, especially if there are hundreds of rows. Reading across a row can sometimes be a challenge. One way of making the table more legible is to alternate the background color of each row. By the way, the plugin used on this blog to display code uses zebra stripes. Zebra stripping can be done by toggling a variable and alternately displaying an odd or even CSS class as it goes through the loop.

The Code:

<pre lang="php">
// set variable initially to "odd."
// loop 4 times for demo purposes.
// toggle CSS classes while in a loop.
$c = "odd";
$count = 0;
echo "

| Data | |—|

”; The Result:

<pre lang="html">
Data
Data
Data
Data

The Style:

<pre lang="css">
.odd { background-color: #fff; }
.even { background-color: #eee; }

To see it in action, visit CodePad.