[英]HTML table how highlight row on hover except first column?
Use :not
and :first-child
to exclude the first cell like so:使用
:not
和:first-child
排除第一个单元格,如下所示:
#myTable tr:hover td:not(:first-child){
background: #ddd;
}
Demo:演示:
#myTable { border-collapse: collapse; } #myTable td { width: 100px; border: 1px solid black; } #myTable tr:hover td:not(:first-child) { background: #ddd; }
<table id="myTable"> <tr> <td>A</td> <td>B</td> <td>C</td> </tr> <tr> <td>1</td> <td>2</td> <td>X</td> </tr> <tr> <td>3</td> <td>4</td> <td>X</td> </tr> </table>
If I'm understanding the end goal, target :hover
on a non :first-child
element, then also select all of the elements that come after it using the general sibling selector.如果我理解最终目标,则将
:hover
在非:first-child
元素上,然后还使用通用同级选择器选择它之后的所有元素。
td:not(:first-child):hover, td:not(:first-child):hover ~ td { background: #eee; }
<table id="myTable"> <tr> <td>A</td> <td>B</td> <td>C</td> </tr> <tr> <td>1</td> <td>2</td> <td>X</td> </tr> <tr> <td>3</td> <td>4</td> <td>X</td> </tr> </table>
Use the :first-child
Selector and a :not
.使用
:first-child
Selector 和:not
。
For example:例如:
#myTable tr:hover td:not(:first-child) {
background: #999;
}
#myTable tr:hover td:not(:first-child) { background: #999; }
<table id="myTable"> <tr><td>A</td><td>B</td><td>C</td></tr> <tr><td>1</td><td>2</td><td>X</td></tr> <tr><td>3</td><td>4</td><td>X</td></tr> </table>
You can use the :not
with :firstchild
like this:您可以像这样使用
:not
和:firstchild
:
$("#myTable tr").hover( function () { $(this).find("td:not(:first-child)").addClass('hoverclass') }, function () { $(this).find("td:not(:first-child)").removeClass('hoverclass') } );
#myTable tr:hover td:not(:first-child) { background-color: #444444; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script> <table id="myTable"> <tr><td>A</td><td>B</td><td>C</td></tr> <tr><td>1</td><td>2</td><td>X</td></tr> <tr><td>3</td><td>4</td><td>X</td></tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.