4

I'm trying to add borders around specific table rows which change it's colors when the mouse enters the row. However, I don't 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>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
wdguru
  • 41
  • 1
  • 2

4 Answers4

12

You can try using outline instead.

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

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

Yi Jiang
  • 49,435
  • 16
  • 136
  • 136
  • 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 Aug 28 '10 at 06:47
  • @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 Aug 28 '10 at 07:27
2

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.

David Thomas
  • 249,100
  • 51
  • 377
  • 410
Pramendra Gupta
  • 14,667
  • 4
  • 33
  • 34
0

i had exactly the same problem and found this workaround:

<tr class="border_bottom">

CSS:

tr.border_bottom td {
   border:1pt solid black;
}

Found it here and adjusted it: Add border-bottom to table row <tr>

Community
  • 1
  • 1
-1

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>
Barnee
  • 3,212
  • 8
  • 41
  • 53
Moin Zaman
  • 25,281
  • 6
  • 70
  • 74
  • 1
    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 Aug 28 '10 at 06:51