html - 我该如何处理这样的表格边框?
问题描述
我希望实现这样的表格边框(注意第 3 行下的粗边框):
所以,我按照下面给出的编码,
body {
font-family: Roboto Condensed;
background-color: hsl(0, 0%, 25%);
color: white;
padding: 2px 5px 2px 5px;
}
table {
border: 2px solid;
border-collapse: collapse;
width: 100%;
}
caption {
font-weight: bold;
border: 2px solid;
border-collapse: collapse;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
}
th {
border: 2px solid;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
background-color: hsla(0, 0%, 50%, .5);
width: 10%;
}
td {
border: 1px solid #ccc;
padding: 8px;
width: 15%;
}
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet" type="text/css">
<table>
<caption>TableCaption</caption>
<tr>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
</table>
它最终是这样的(注意第三行下的边框不厚):
现在我想知道以哪种方式处理表格边框,以便获得预期的结果。
解决方案
您可以尝试将第 n 个子项用于表格行,如下所示:
tr:nth-child(3) {
border-bottom: 2px solid white;
}
在这里,我更新了您的代码片段:
body {
font-family: Roboto Condensed;
background-color: hsl(0, 0%, 25%);
color: white;
padding: 2px 5px 2px 5px;
}
table {
border: 2px solid;
border-collapse: collapse;
width: 100%;
}
caption {
font-weight: bold;
border: 2px solid;
border-collapse: collapse;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
}
th {
border: 2px solid;
padding: 8px;
padding-top: 12px;
padding-bottom: 12px;
background-color: hsla(0, 0%, 50%, .5);
width: 10%;
}
td {
border: 1px solid #ccc;
padding: 8px;
width: 15%;
}
tr:nth-child(3) {
border-bottom: 2px solid white;
}
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet" type="text/css">
<table>
<caption>TableCaption</caption>
<tr>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
<th>TableHeader</th>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<th rowspan="2">SpannedRow1</th>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
<tr>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
<td>TableData</td>
</tr>
</table>
推荐阅读
- python - 日志实例类
- karate - 参数未占用 %2B
- arrays - 增加 excel vba 数组中的最大元素数
- javascript - Web App Script - 如何从问题中提取值以用于搜索以填充另一个问题?
- hyperledger-fabric - 安装链码时出错 - 无法计算依赖项:包不完整
- assembly - Windows 10 程序集 HELLO WORLD 尝试失败
- java - 在 IBM i 7.4 上配置 IBM JDK 版本 JAVA_HOME 不能从 java 1.6 到 1.7/1.8 工作
- mysql - laravel 中无法获取关系数据
- javascript - 如何使用 Scaledrone 刷新所有连接的客户端?
- ios - Xcode 强制我使用 contains(where:) 而不是 contains()