Reputation: 15925
I have a table
and I want to style at tr
level. This does not work on IE7 if I apply the style directly to the tr
.
What's the best way to go about styling the table
so I get a line across all rows but have no line at the very top or at the very bottom.
So basically, the table should look something like this
col1 col2 col3
--------------
col1 col2 col3
--------------
col1 col2 col3
--------------
col1 col2 col3
Upvotes: 1
Views: 101
Reputation: 7802
you can use the last-child selector:
have a look at this fiddle:
EDIT: can you change the html of your table, you could put your first row in the thead, and the rest of your rows in the tbody, and then use
table tbody tr td{
border-top:1px solid red;
}
updated fiddle: http://jsfiddle.net/SGfQy/1/
Upvotes: 0
Reputation: 437454
You can do this without the :last-child
selector, in a way that is also compatible with IE7. And of course without JavaScript:
table tr + tr td {
border-top: 1px black solid;
}
Actually you are using the top border to draw a line, taking advantage of the fact that the tr + tr
selector will match all rows except the first one.
Upvotes: 3
Reputation: 1380
Use CSS2 selectors:
table#mytable tr{
border-bottom:1px solid black;
}
table#mytable tr:last-child{
border-bottom:none;
}
Upvotes: 1
Reputation: 1221
To get a border on the bottom of each row:
table tr td {
border-bottom: 1px solid #000;
}
Then you would need to use some javascript to change the style of the last one, or use css which is probably not supported in IE6/7
table tr:last-child td {
border-bottom: none;
}
example: http://jsbin.com/ezolur
Upvotes: 1