Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outline table row on hover

I am trying to highlight the border of a table row on hover. Unfortunately this only works for the first row of cells. Lower rows have one border that does not change color. I have tried using outline but it doesn't play nice with :hover in webkit.

http://jsfiddle.net/S9pkM/2/

Imagine your standard table html. Some tr's with some td's. Hovering over a row should highlight its border in red.

table { border-collapse: collapse; } /*I am aware of separate */
table td { border: 3px solid black; }
table tr:hover td { border-top-color: red; border-bottom-color: red; }
table tr:hover td:first-child { border-left-color: red; }
table tr:hover td:last-child  { border-right-color: red; }

I am open to alternate approaches, but I am stuck with the table structure. No inserting additional html besides standard <table> <tr> <td>

like image 832
mrtsherman Avatar asked Nov 14 '11 21:11

mrtsherman


People also ask

How to highlight a table row on hover?

You can use CSS without any javascript to make the row of a table highlight on hover. All it requires is that the use the pseudo class :hover to add the effect to whatever html element you choose.

How do you highlight a row in HTML?

className="highlight"; else row. className="normal"; If your table row is currently set as normal, the function will change it to have a status of highlight. If it is currently highlighted, the function will change it back to normal.


1 Answers

I've been facing this same problem and finally found a simpler solution here.

You can use this CSS trick ( border-style: double; ) that works for 1px borders:

#mytable tr.row:hover td
{
    border-style: double;
    border-color: red;
}

This will make your border-color work (be the top most one) no matter what. :-)

like image 197
Leniel Maccaferri Avatar answered Sep 22 '22 09:09

Leniel Maccaferri