我正在尝试使用 CSS 和 :hover 更改我整个 tbody 的背景颜色。当已经设置背景时,我无法更改悬停背景。我根本做不到。我什至尝试过 !impotant 但没有运气。
<table border="1">
<tbody>
<tr>
<th>Testing</th>
<td>Some stuff</td>
</tr>
<tr>
<th>Testing</th>
<td>Second more stuff</td>
</tr>
</tbody>
</table>
我的 CSS
th {
background: red;
}
tbody:hover {
background: blue !important;
}
如您所见,如果未设置背景,悬停效果很好。从 th-tag 中移除 background: red,看看它是否可以在没有预设颜色的情况下工作。
最佳答案
这将为您完成工作,不需要!重要
:
th {
background: red;
}
tbody:hover,
tbody:hover th {
background: blue;
}
关于html - 在具有预设背景颜色的表中悬停时更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21196199/