tags:

views:

55

answers:

3

I'm trying to add borders around specific table rows which change it's colors when the mouse enters the row. However, I dont see a border at all unless using border-collapse:collapse; but I have to avoid border-collapse, since in some cases the border is visible left, right and at bottom but not on top (probably because I cannot have padding/margin when using border-collapse).

Is there a way to achieve this?

<table style="border-collapse:collapse;">

<tr style="border:1px solid black">

<td>Cell_1</td>

<td>Cell_2</td>

</tr>

</table>

+2  A: 

You can try using outline instead.

tr:hover {
    outline: 1px solid #999;
}

Have a look: http://jsfiddle.net/dWWkx/3/

Yi Jiang
Thanks, this seems to be exacly I was looking for. However, I dont see the borders with Google Chrome, while Firefox 3.6 displays it as expected. Strange...
wdguru
@wdguru Hmm... the problem with the outline property is that its used more as a debugging tool than anything else, since the position of the border is not defined clearly in the specs. Its possible that Webkit does not support outline on `tr` - IE 7 and below does not support this at all. See: http://reference.sitepoint.com/css/outline
Yi Jiang
A: 

try this:

<table style="">

<tr style="display:block;border:1px solid black">

<td>Cell_1</td>

<td>Cell_2</td>

</tr>

<tr style="display:block;border:1px solid black">

<td>Cell_1</td>

<td>Cell_2</td>

</tr>

</table>
Moin Zaman
Thanks, but I've tried this before. The problem with display:block is, that the row isn't streched as it would be with display:table-row.
wdguru
A: 

As far as I know you can't put a border on a table row, but you can on the table cell (<td>). With some creative border-right and border-left, with a cell-spacing of 0, you should be able to achieve the appearance of a border around the whole row.

JapanPro