Outline table row on hover

后端 未结 4 1206
说谎
说谎 2021-02-19 07:23

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 h

4条回答
  •  盖世英雄少女心
    2021-02-19 08:04

    For 1px borders see Leniel's solution that uses border-style: double. This is much simpler. A double border is one that shows a 1px line for the inside and outside edges of the border. This doesn't do anything for a 1px border, but on >1px there is a gap.

    For borders >1px you remove the bottom border for all of the 's with border-bottom: 0. The top borders of the other cells will keep everything looking the way they should, except for the last row. The last row we fix with tr:last-child td { border-bottom: your border style }. Finally in your hover pseudoclass you set the bottom border.

    http://jsfiddle.net/S9pkM/16/

    table { border-collapse: collapse; } /*I am aware of separate */
    table td { border: 1px solid black; width: 50px; height: 25px; padding: 5px; border-bottom: 0; }
    table tr:last-child td { border-bottom: 1px solid black; }
    table tr:hover td { border-top-color: red; border-bottom: 1px solid red; }
    table tr:hover td:first-child { border-left-color: red; }
    table tr:hover td:last-child  { border-right-color: red; }
    

提交回复
热议问题