Forum Moderators: not2easy
table > tbody > tr + tr > td {
border-bottom: 1px solid #EFEFEF !important;
}
table > tbody > tr:last-child > td:last-child {
border-bottom: 0px !important; /* removes border from last cell in table */
} The issue here is that it only does every other for the first two. It looks like:
1
2
--
3
--
4
--
5
--
6
--
When I want it to look like:
1
2
--
3
4
--
5
6
--
I know the issue is that it is only reading tr + tr once, but how can I get it to repeat that? Note: I've tried taking away the "table > body > " -- I don't know how to repeat in CSS.
table > tbody > tr + tr > td
[edited by: DrDoc at 5:54 pm (utc) on July 3, 2008]
[edit reason] fixed [codes] [/edit]
You might be able to get around it by wrapping each 2 tr elements in a tbody element:
<table>
<tbody>
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
</tbody>
<tbody>
<tr>
<td>3</td>
</tr>
<tr>
<td>4</td>
</tr>
</tbody>
<tbody>
<tr>
<td>5</td>
</tr>
<tr>
<td>6</td>
</tr>
</tbody>
</table>
[w3.org...]
Aside of that, if you can give the rows even and odd classes: it'll make your life a lot easier if you still need to get e.g. IE6 on board.
Also try to make the first element special, not the last, as IE only does :first-child not :last-child (I know childish ;-) of them browser crafters, but unfortunately something we're forced to live with)
if it's a small table or fairly controlled with amount of rows involved a yuk rule like this might do you..
this uses specificity, as mentioned, to overide each row, the mjore rows the more selectors each rule will need, this is for 6 as per your example..
/* rows 1, 3 & 5 - count the tr selectors */
tr td,
tr+tr+tr td,
tr+tr+tr+tr+tr td
{border: 0;}/* rows 2, 4 & 6 - count the tr selectors */
tr+tr td,
tr+tr+tr+tr td,
tr+tr+tr+tr+tr+tr td
{border-bottom: 3px solid #f00;}
or as advised above if you use :first-child, in combination with the adjacent siblings and you half the rule
/* rows 2, 4 & 6 - count the tr selectors */
tr:first-child+tr td,
tr:first-child+tr+tr+tr td,
tr:first-child+tr+tr+tr+tr+tr td
{border-bottom: 3px solid #f00;}
just in case, both of the above solutions will only have support in IE7 and above though