悬停thead元素时更改tbody元素

时间:2020-06-03 13:25:48

标签: html css

是否可以仅通过CSS在tbody元素上更改thead元素?我搜索了该主题,但仅涉及父div的内部div元素。

thead th {
  background-color: wheat;
}

thead th:hover {
  background-color: red;
}

thead th:hover tbody td {
  background-color: red;
}

tbody td {
  background-color: green;
}
<div class="one">
   <table>
     <thead><tr><th>qqqqq</th></tr></thead>
     <tbody><tr><td>wwwww</td></tr></tbody>
   </table>
</div>

1 个答案:

答案 0 :(得分:0)

是的,您可以:

thead th {
  background-color: wheat;
}

thead th:hover {
  background-color: red;
}

thead:hover + tbody td {
  background-color: red;
}

tbody td {
  background-color: green;
}
<div class="one">
   <table>
     <thead><tr><th>qqqqq</th></tr></thead>
     <tbody><tr><td>wwwww</td></tr></tbody>
   </table>
</div>