Following a table row across the screen can sometimes be hard on your eyes. I use CSS, and Javascript to color the rows alternately to make it easier on my visitors:
<style type="text/css">
.zebra1 th {
background-color: #ffffcc;
color: black;
}
.zebra1 td {
background-color: #00ffff;
color: black;
}
.zebra1 .tdata2 {
background-color: #ccffff;
color: black;
}
</style>
<script type="text/javascript">
function ZebraTables() {
ZT_tables=document.getElementsByTagName('table');
for (ZT_ix1=0; ZT_ix1<ZT_tables.length; ZT_ix1++) {
ZT_table=ZT_tables[ZT_ix1];
ZT_className=ZT_table['className'];
if (ZT_className.indexOf('zebra1') > -1) {
ZT_tBodies=ZT_table.tBodies;
for (ZT_ix2=0; ZT_ix2<ZT_tBodies.length; ZT_ix2++) {
ZT_tBody=ZT_tBodies[ZT_ix2];
ZT_rows=ZT_tBody.rows;
ZT_oddRow='true';
for (ZT_ix3=0; ZT_ix3<ZT_rows.length; ZT_ix3++) {
ZT_oddRow=!ZT_oddRow;
if (ZT_oddRow) {
ZT_row=ZT_rows[ZT_ix3];
ZT_cells=ZT_row.cells
for (ZT_ix4=0; ZT_ix4<ZT_cells.length; ZT_ix4++) {
ZT_cell=ZT_cells[ZT_ix4];
ZT_className4=ZT_cell.className;
ZT_bgColor=ZT_cell.getAttribute('bgColor');
if (!ZT_bgColor) { ZT_bgColor=''; }
if ((!ZT_className4) && (!ZT_bgColor)) {
ZT_cell.className='tdata2';
}
} // end of cells
} // end of oddRow
} // end of rows
} // end of tbodies
} // end of 'zebra1' class
} // end of tables
} // ZebraTables
window.onload=ZebraTables;
</script>
-------------------------------------------------------
<table class="zebra1" border="1">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>value 1-1</td>
<td>value 1-2</td>
</tr>
<tr>
<td>value 2-1</td>
<td>value 2-2</td>
</tr>
<tr>
<td>value 3-1</td>
<td>value 3-2</td>
</tr>
</tbody>
</table>
The above code produces this table:
| Column 1 | Column 2 |
|---|---|
| value 1-1 | value 1-2 |
| value 2-1 | value 2-2 |
| value 3-1 | value 3-2 |