首页 > 解决方案 > 我该如何处理这样的表格边框?

问题描述

我希望实现这样的表格边框(注意第 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>

它最终是这样的(注意第三行下的边框不厚):

在此处输入图像描述

现在我想知道以哪种方式处理表格边框,以便获得预期的结果。

标签: htmlcsshtml-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>


推荐阅读