I am trying to come up with a style my rows with odd/even styles. The row is going to be marked with class odd/even but the style needs to apply to the containing td/th.
The reason the style can't be placed directly on the row is because applying background colors to the row instead of the td/th causes inconsistent results in certain browsers.
When I apply the color to the td/th it causes problem in nested scenarios.
<html><head><title>Nesting</title></head><body>
<style type="text/css">
.even td, .even th {
background-color: #FBFCFD;
}
.odd td, .odd th {
background-color: #FEFFFF;
}
</style>
<table width="100%">
<tr class="even">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="odd">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="even">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="odd">
<th>Test</th>
<td>
<table width="100%">
<tr class="even">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="odd">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="even">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="odd">
<th>Test</th>
<td>
<table width="100%">
<tr class="even">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="odd">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="even">
<th>Test</th>
<td>Test</td>
</tr>
<tr class="odd">
<th>Test</th>
<td>Test</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body></html>
What would be ideal is if I could do something like the following, but unfortunately it does work in older browsers.
<style type="text/css">
.even > td, .even > th {
background-color: #FBFCFD;
}
.odd > td, .odd > th {
background-color: #FEFFFF;
}
</style>
See the problem live - http://jsfiddle.net/fB9Db/