gpt4 book ai didi

html - 当 tbody 悬停时覆盖元素的样式

转载 作者:太空宇宙 更新时间:2023-11-03 20:31:12 26 4
gpt4 key购买 nike

我在 :hover 中遇到问题.

我想做最后一个tr其中tbody当它的 tbody 时也会改变颜色悬停。问题是最后tr有自己的类(class)。

这是我的代码结构:

.cust-table {
border: 1px solid black;
border-collapse: collapse;
width: 100%;
}

.cust-table td {
border: 1px solid black;
padding: 10px;
}

.cust-table tbody:nth-child(even){
background-color: white;
}

.cust-table tbody:nth-child(odd){
background-color: green;
}

.cust-color {
background-color: blue;
}

.cust-table tbody:hover {
background-color: yellow;
}
<table class="cust-table">
<tbody>
<tr>
<td rowspan="2">A</td>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr class="cust-color">
<td colspan="3">Cust color</td>
</tr>
</tbody>
<tbody>
<tr>
<td rowspan="2">B</td>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr class="cust-color">
<td colspan="3">Cust color</td>
</tr>
</tbody>
<tbody>
<tr>
<td rowspan="2">C</td>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr class="cust-color">
<td colspan="3">Cust color</td>
</tr>
</tbody>
</table>

我尝试添加 cust-color:hover但正如预期的那样,它仅在 <tr> 时有效与 cust-color悬停。

最佳答案

仅当 tbody 未悬停时才使用此规则设置自定义颜色:

tbody:not(:hover) .cust-color {
background-color: blue;
}

.cust-table {
border: 1px solid black;
border-collapse: collapse;
width: 100%;
}

.cust-table td {
border: 1px solid black;
padding: 10px;
}

.cust-table tbody:nth-child(even){
background-color: white;
}

.cust-table tbody:nth-child(odd){
background-color: green;
}

tbody:not(:hover) .cust-color {
background-color: blue;
}

.cust-table tbody:hover {
background-color: yellow;
}
<table class="cust-table">
<tbody>
<tr>
<td rowspan="2">A</td>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr class="cust-color">
<td colspan="3">Cust color</td>
</tr>
</tbody>
<tbody>
<tr>
<td rowspan="2">B</td>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr class="cust-color">
<td colspan="3">Cust color</td>
</tr>
</tbody>
<tbody>
<tr>
<td rowspan="2">C</td>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr>
<td>Col 1</td>
<td>Col 2</td>
</tr>
<tr class="cust-color">
<td colspan="3">Cust color</td>
</tr>
</tbody>
</table>

关于html - 当 tbody 悬停时覆盖元素的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41751930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com