HTML Table - Vertical Zebra Stripes | Tables
To make vertical zebra stripes, style every other column, instead of every other row.
Set the :nth-child(even)
for table data elements like this:
<!DOCTYPE html>
<html>
<head>
<title>HTML Table - Vertical Zebra Stripes</title>
</head>
<body>
<h2>Vertical Zebra Stripes</h2>
<p>For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd) table rows:</p>
<table style="width:100%">
<tr>
<th>MON</th>
<th>TUE</th>
<th>WED</th>
<th>THU</th>
<th>FRI</th>
<th>SAT</th>
<th>SUN</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
Note: Put the :nth-child()
selector on both th
and td
elements if you want to have the styling on both headers and regular table cells.