html - 如何使用css将边框添加到带有th的tr
问题描述
我已经建立了一个网页,其中包含一些带有侧标题的表格。这是我的标记:
<table id="talents">
<thead>
<!-- ... -->
</thead>
<tbody>
<tr>
<th scope="rowgroup" rowspan="3">Investigator</th>
<td>At 3rd: Expanded Inspiration (Ex)</td>
<td>Free insp. on Diplomacy, Heal, Perception, Profession, Sense Motive.</td>
</tr>
<!-- more trs falling into the above rowgroup -->
<tr>
<th scope="rowgroup" rowspan="4">Rogue</th>
<td>At 2nd: Positioning Attack</td>
<td>Once per day move up to 30ft. to spot adjacent to creature attacked.</td>
</tr>
<!-- more trs falling into the above rowgroup -->
</tbody>
</table>
我想对这些border-top
行组之间的边框进行样式设置,比如将 a 添加到包含<th>Rogue</th>
. 如果可能的话,我对纯 CSS 解决方案很感兴趣——一种无需在行中添加类或 id<th>
或其他东西的方法。
顺便说一句,实验性的 :has() 选择器似乎很简单:
tbody tr:has(> th) { border-top: 2px solid black; }
但仍然没有浏览器支持:has()
. 有支持的替代方案吗?
解决方案
你可以使用这样的东西,
table {
border-collapse: collapse;
}
tbody tr>th,
tbody tr>th~td {
border-top: 2px solid black;
}
<table id="talents">
<thead>
<!-- ... -->
</thead>
<tbody>
<tr>
<th scope="rowgroup" rowspan="2">Investigator</th>
<td>At 3rd: Expanded Inspiration (Ex)</td>
<td>Free insp. on Diplomacy, Heal, Perception, Profession, Sense Motive.</td>
</tr>
<tr>
<td>At 3rd: Expanded Inspiration (Ex)</td>
<td>Free insp. on Diplomacy, Heal, Perception, Profession, Sense Motive.</td>
</tr>
<!-- more trs falling into the above rowgroup -->
<tr>
<th scope="rowgroup" rowspan="4">Rogue</th>
<td>At 2nd: Positioning Attack</td>
<td>Once per day move up to 30ft. to spot adjacent to creature attacked.</td>
</tr>
<!-- more trs falling into the above rowgroup -->
</tbody>
</table>
推荐阅读
- c# - 手动处理装配加载
- php - 如何在没有性能开销的情况下将 Xdebug 模块加载到 PHP 中?
- javascript - 意外值 - e.target.value
- angular - 如何根据 Token 的值使用 *ngIf 渲染组件?
- bash - 如何在 shell 脚本中在当前目录之前打印目录?
- javascript - 如何在 Laravel mix Vue Js 上动态创建组件 Navbar
- mysql - 如何为 cli 和应用程序使用 DoctrineORMModule 不同的凭据?
- paypal - PayPal 支付体验配置文件创建
- node.js - AWS EC2 实例中的 puppeteer 集群脚本问题
- r - 如何使用相同的 R 代码运行多个 Excel 工作表