将样式更改为 HTML 表中的标题



我正在学习 html 表格的 css 编写风格,我想知道如何删除标题第一行空白单元格的边框,以及圆润单元格的边缘estimated amounttotal

除了复制线程之外,我还保留了 html 和 css:

table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
.blank {
background-color: #FFFFFF; 
}
table tr {
background-color: #f8f8f8;
border: 2px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
<table>
<thead>
<tr>
<th class="blank"></th>
<th colspan="2">estimated amount</th>
<th>total</th>
</tr>
<tr>
<th scope="col">Account</th>
<th scope="col">Expense</th>
<th scope="col">Income</th>
<th scope="col">Diff</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$3,190</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$2,190</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$5,000</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$4,000</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$7,000</td>
<td data-label="Income">$4,000</td>
<td data-label="Diff">$3,000</td>
</tr>
</tbody>
</table>

这是一个棘手的问题,因为在将边框折叠的值设置为折叠的同时应用边框半径将无法按您想要的方式工作。

我给你的解决方案是使用CSS创建边框,如下所示:

table {

border-collapse: separate;
border-spacing: 0;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}

th ,td {
border-right:2px solid #ddd;
border-bottom: 2px solid #ddd;
background-color: #f8f8f8;
padding: .35em;
}
#tr1 th:last-child {
border-top: 2px solid #ddd;
}
#tr1 th:nth-child(2) {
border-left: 2px solid #ddd;
border-top: 2px solid #ddd;
}
#tr2 th:first-child{
border-top: 2px solid #ddd;
}
#tr2 th:first-child{
border-left: 2px solid #ddd;
}
tr td:first-child{
border-left: 2px solid #ddd;
}
.blank {
background-color: #FFFFFF;
border: none;
}
.estimatedAmountClass {
border-top-left-radius: 40px;
}
.totalClass {
border-top-right-radius: 40px;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
<table >
<thead>
<tr id="tr1">
<th class="blank"></th>
<th class="estimatedAmountClass" colspan="2">estimated amount</th>
<th class="totalClass">total</th>
</tr>
<tr id="tr2">
<th scope="col">Account</th>
<th scope="col">Expense</th>
<th scope="col">Income</th>
<th scope="col">Diff</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$3,190</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$2,190</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$5,000</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$4,000</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$7,000</td>
<td data-label="Income">$4,000</td>
<td data-label="Diff">$3,000</td>
</tr>
</tbody>
</table>

相关内容

  • 没有找到相关文章

最新更新