html - 如何使用 CSS 正确悬停 rowSpan 单元格
问题描述
考虑以下具有跨行行的简单表:
.grid {
border-collapse: collapse;
table-layout: fixed;
border: 1px solid black;
}
.headerrow {
border: 1px solid black;
width: 100px;
border: 1px solid black;
}
.row {
border: 1px solid black;
width: 100px;
border: 1px solid black;
}
.cell {
padding: 10px;
border: 1px solid black;
text-align: center;
}
.row:hover {
background-color: grey;
color: white;
}
<table class="grid">
<thead>
<tr class="headerrow">
<th class="cell"><input type="checkbox"></th>
<td class="cell">
Column 1
</div>
</td>
<td class="cell">
Column 2
</div>
</td>
<td class="cell">
Column 3
</div>
</td>
<td class="cell">
Column 4
</div>
</td>
<td class="cell">
Column 5
</div>
</td>
</tr>
</thead>
<tbody>
<tr class="row">
<td class="cell" rowspan="2"><input type="checkbox"></td>
<td rowspan="2" class="cell">
0
</td>
<td class="cell">
0
</td>
<td rowspan="2" class="cell">
0
</td>
<td class="cell">
0
</td>
<td class="cell">
0
</td>
</tr>
<tr class="row">
<td class="cell">
2
</td>
<td class="cell">
4
</td>
<td class="cell">
5
</td>
</tr>
<tr class="row">
<td class="cell"><input type="checkbox"></td>
<td rowspan="1" class="cell">
2
</td>
<td class="cell">
4
</td>
<td rowspan="1" class="cell">
6
</td>
<td class="cell">
8
</td>
<td class="cell">
10
</td>
</tr>
</tbody>
</table>
使用纯 CSS,如何调整悬停行为以在两行(具有 rowSpan 的行和下一行)上发生,如下所示:
解决方案
不能,因为不一样<td>
一种选择是将其分组<tbody>
.grid {
border-collapse: collapse;
table-layout: fixed;
border: 1px solid black;
}
.headerrow {
border: 1px solid black;
width: 100px;
border: 1px solid black;
}
.row {
border: 1px solid black;
width: 100px;
border: 1px solid black;
}
.cell {
padding: 10px;
border: 1px solid black;
text-align: center;
}
tbody:hover {
background-color: grey;
color: white;
}
<table class="grid">
<thead>
<tr class="headerrow">
<th class="cell"><input type="checkbox"></th>
<td class="cell">
Column 1
</div>
</td>
<td class="cell">
Column 2
</div>
</td>
<td class="cell">
Column 3
</div>
</td>
<td class="cell">
Column 4
</div>
</td>
<td class="cell">
Column 5
</div>
</td>
</tr>
</thead>
<tbody>
<tr class="row">
<td class="cell" rowspan="2"><input type="checkbox"></td>
<td rowspan="2" class="cell">
0
</td>
<td class="cell">
0
</td>
<td rowspan="2" class="cell">
0
</td>
<td class="cell">
0
</td>
<td class="cell">
0
</td>
</tr>
<tr class="row">
<td class="cell">
2
</td>
<td class="cell">
4
</td>
<td class="cell">
5
</td>
</tr>
</tbody>
<tbody>
<tr class="row">
<td class="cell"><input type="checkbox"></td>
<td rowspan="1" class="cell">
2
</td>
<td class="cell">
4
</td>
<td rowspan="1" class="cell">
6
</td>
<td class="cell">
8
</td>
<td class="cell">
10
</td>
</tr>
</tbody>
</table>
推荐阅读
- javascript - 在 Laravel + Vue 上 @click 事件时获取旧数据
- javascript - Javascript/Python - 单击网站上的按钮并在 python 中运行函数
- python - 选择列时的Python panda keyerror
- c++ - 如何使用arm64程序集进行浮点运算?
- linux - 在 Linux 上调试 Webkitgtk
- bash - 使用 docker-compose 命令编写脚本。一行未执行
- html - 渲染期间不翻译 HTML 字符
- python - 附加 HDFStore 熊猫 TypeError
- sql - 如何提取范围内的日期?
- python - 如何从字符串中删除“\x80”