[英]table styling - is it possible for a td:hover rule to override a tr:hover?
I was wondering if it's possible to have a table styled with :hover
background rules for both a tr and a td with certain class so that when the particular td is hovered on, only that element gets the background applied and not the tr it's within.我想知道是否有可能为具有特定类的 tr 和 td 设置一个带有
:hover
背景规则样式的表格,以便当悬停特定 td 时,只有该元素会应用背景,而不是它所在的 tr。
So for example:例如:
tr:hover { background: blue; } td.something:hover { background: yellow; }
<table> <tr> <td></td> <td></td> <td class="something"></td> </tr> <table>
Here I'd like the table to highlight the row if the first two td elements are hovered, but not on the third td with the something
css class.在这里,如果前两个 td 元素悬停,我希望表格突出显示该行,而不是在带有
something
css 类的第三个 td 上。
I was wondering if the :not
selector could help somehow, but I haven't come up with a way yet.我想知道
:not
选择器是否能以某种方式提供帮助,但我还没有想出办法。 Is this possible?这可能吗?
Thanks谢谢
I think this is what you want:我认为这就是你想要的:
tr:hover { background: blue; } tr:hover td.something { background: #FFF; } tr:hover td.something:hover { background: yellow; }
<table> <tr> <td>aaa</td> <td>aaa</td> <td class="something">dddd</td> </tr> <table>
You can except tags with your css class as following您可以使用 css 类除标签,如下所示
table { border: 1px solid blue; } tr:hover td:not(.something) { background: blue; }
<table> <tr> <td>Cell 1</td> <td>Cell 2</td> <td class="something">Cell 3</td> </tr> <table>
Or if you want to some cells with bg yellow and some with blue same time:或者,如果您想要一些带有 bg 黄色和一些带有蓝色同时的单元格:
tr:hover td:not(.something) { background: blue; } tr:hover td:not(.anotherthing) { background: yellow; }
<table> <tr> <td class="anotherthing">Cell 1</td> <td class="anotherthing">Cell 2</td> <td class="something">Cell 3</td> </tr> <table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.