For a project, I need to create a table with alternating column background colors. However, there are certain rows that need to span multiple columns while maintaining the correct background color for each cell.
You can view the code on this jsfiddle link, or check out the CSS:
body {
font-family:Calibri, Trebuchet MS, Verdana, Tahoma, sans-serif;
}
table {
border:1px solid #444;
text-align:center;
}
th, td {
width:200px;
padding:2px;
}
.lg {
background-color:#eee;
}
.dg {
background-color:#ddd;
}
}
Here is the corresponding HTML:
<table>
<tr>
<th>Fruits</th>
<td class="lg">Peach</td>
<td class="dg">Blueberry</td>
<td class="lg">Apple</td>
</tr>
<tr>
<th>Chocolate</th>
<td class="lg">Chocolate-Chip</td>
<td class="dg">Double Chocolate</td>
<td class="lg">Turtle</td>
</tr>
<tr>
<th>Peanut Butter</th>
<td colspan="3">Peanut Butter Swirl and a long list of items</td>
</tr>
<tr>
<th>Classics</th>
<td class="lg">Chocolate</td>
<td class="dg">Vanilla</td>
<td class="lg">Strawberry</td>
</tr>
</table>
I currently have a background image in place to mimic the effect of spanning columns. However, it doesn't align perfectly no matter what I try, especially in Opera as it looks completely off. This is a fixed-width table. Is there a reliable way to achieve this consistently?