gpt4 book ai didi

html - 解决表格圆 Angular CSS

转载 作者:搜寻专家 更新时间:2023-10-31 21:56:50 26 4
gpt4 key购买 nike

我有圆 Angular 的 CSS 规则:

th, td { padding: 8px;
background: #E8ECE0;
text-align: center;
border: 1px solid #444;
border-bottom-width: 0px;
}
thead { background-color: #446bb3 ; color :#fff; padding:4px; line-height:30px }
tbody tr:nth-child(even) {background: #F6F6EC;}
tbody tr:nth-child(odd) {background: #FFF}

tr:first-child td, tr:first-child th {
border-top-left-radius: 12px; border-top-right-radius: 12px;
}
tr:last-child td {
border-bottom: 1px solid #444;
border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;
}
table { border-spacing: 0; border: 0; margin:0px; width:100%; padding:5px}
td.pd {border-bottom-left-radius: 12px; border-bottom-right-radius: 12px;}
td.pu {border-top-left-radius: 12px; border-top-right-radius: 12px;}

我的 html 表是:

<table >
<tbody>
<tr >
<td >Hello</td><td >Hello</td>
</tr>
<tr >
<td >Hello</td><td >Hello</td>
</tr>
<tr >
<td >Hello</td><td >Hello</td>
</tr>
<tr >
<td >Hello</td><td >Hello</td>
</tr>
</tbody>
</table>

这给了我这个

table with rounded corner

我该如何解决这个问题,因为表格内和表格中间的 td 元素也有圆 Angular ?我只需要第一行和最后一行有圆 Angular 。

最佳答案

假设您的 table 的 html 类似于以下内容:

<table>
<thead>
<tr>
<th>First column</th>
<th>Second column</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row one, cell one</td>
<td>Row one, cell two</td>
</tr>
<tr>
<td>Row two, cell one</td>
<td>Row two, cell two</td>
</tr>
<tr>
<td>Row three, cell one</td>
<td>Row four, cell two</td>
</tr>
</tbody>
</table>

以下 CSS 应该可以工作:

table {
border-spacing: 0;
}
th, td {
border: 1px solid #000;
padding: 0.5em 1em;
}
/* the first 'th' within the first 'tr' of the 'thead': */
thead tr:first-child th:first-child {
border-radius: 0.6em 0 0 0;
}
/* the last 'th' within the first 'tr' of the 'thead': */
thead tr:first-child th:last-child {
border-radius: 0 0.6em 0 0;
}
/* the first 'td' within the last 'tr' of the 'tbody': */
tbody tr:last-child td:first-child {
border-radius: 0 0 0 0.6em;
}
/* the last 'td' within the last 'tr' of the 'tbody': */
tbody tr:last-child td:last-child {
border-radius: 0 0 0.6em 0;
}

JS Fiddle demo .

针对 OP 的问题进行编辑:

the border within the table is a little think, how do i make it 1px

单元格之间的边框有点粗,因为一个单元格的左边框与前一个单元格的右边框相对(顶部/底部边框也是如此)。

消除这种影响的一种方法是在 table 元素上指定 border-collapse: collapse;。不幸的是,这样做的效果是删除/取消设置/覆盖border-radius 声明:demo .

更复杂的方法是手动删除前一行的行的上边框,以及单元格后面的单元格的左边框,将以下内容添加到前面的 CSS:

thead + tbody tr td,
tr + tr td {
border-top: 0;
}

tr th + th,
tr td + td {
border-left: 0;
}

JS Fiddle demo .

编辑以减少使 CSS 更耐用(对于单单元格行,添加 tfoot 或删除 thead):

table {
border-spacing: 0;
}
th, td {
border: 1px solid #000;
padding: 0.5em 1em;
}
thead tr:first-child th:first-child,
tbody:first-child tr:first-child td:first-child {
border-top-left-radius: 0.6em;
}
thead tr:first-child th:last-child,
tbody:first-child tr:first-child td:last-child {
border-top-right-radius: 0.6em;
}

thead + tbody tr:last-child td:first-child,
tfoot tr:last-child td:first-child {
border-bottom-left-radius: 0.6em;
}
thead + tbody tr:last-child td:last-child,
tfoot tr:last-child td:last-child {
border-bottom-right-radius: 0.6em;
}

thead + tbody tr td,
tfoot + tbody tr td,
tfoot tr td,
tbody + tbody tr td,
tr + tr td {
border-top: 0;
}

tr th + th,
tr td + td {
border-left: 0;
}

JS Fiddle demo .

多个tbody元素存在问题,在没有tfoot元素的情况下,目前第一个tbody将保留下边界上的边界半径。

关于html - 解决表格圆 Angular CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16635182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com