css - 如何在桌子的每个 tr 上制作圆角
问题描述
我正在尝试制作一个表格,其中每个 tr 都有圆角,如下图所示。
我试过下面的CSS代码。
.newTable {
border-collapse: separate;
border-spacing: 0;
}
.newTable td {
border: solid 1px #000;
border-style: none solid solid none;
padding: 10px;
}
.newTable tr:first-child td:first-child {
border-top-left-radius: 10px;
}
.newTable tr:first-child td:last-child {
border-top-right-radius: 10px;
}
.newTable tr:last-child td:first-child {
border-bottom-left-radius: 10px;
}
.newTable tr:last-child td:last-child {
border-bottom-right-radius: 10px;
}
.newTable tr:first-child td {
border-top-style: solid;
}
.newTable tr td:first-child {
border-left-style: solid;
}
但它给了我这样的结果
解决方案
问题是在表格tr
中不喜欢采用样式,因此您需要将border-radius
AND添加background-color
到行中。
此外,由于您可以拥有 N 个表格单元格,我们将使用:first-child
and:last-child
仅更改td
每行中第一个/最后一个的半径。
可以通过使用border-spacing
表本身的属性来分隔行。
这是一个与您的插图相匹配的示例。
table {
width: 500px;
margin: 20px;
border-collapse: separate;
border-spacing: 0 10px;
}
td {
padding: 5px;
text-align: center;
background-color: #eee;
}
td:first-child {
border-radius: 10px 0 0 10px;
}
td:last-child {
border-radius: 0 10px 10px 0;
}
<table cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Header</th>
<th>Header</th>
<th>Header</th>
<th>Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>cell</td>
<td>cell</td>
<td>cell</td>
<td>cell</td>
</tr>
<tr>
<td>cell</td>
<td>cell</td>
<td>cell</td>
<td>cell</td>
</tr>
<tr>
<td>cell</td>
<td>cell</td>
<td>cell</td>
<td>cell</td>
</tr>
</tbody>
</table>
推荐阅读
- svelte - 有没有更好的方法可以使用 dexie 在 svelte 中编写此代码?
- apache - 内容安全策略正在阻止 Firefox 中的 svg 图标精灵
- google-chrome-extension - Firefox 扩展共享异步函数返回给 => 错误:访问属性“then”的权限被拒绝
- javascript - 为什么这在更改用户名时不会自行呈现。从火力基地得到反应
- javascript - 在任何图表中更改弧线颜色和值
- python - 我在使用 Tweepy 时遇到错误,我不确定为什么它说我正在通过更多职位
- wordpress - Wordpress - 在单页上显示类别
- monetdb - 使用 WITH 的 UPDATE 语句在 MonetDB 中不起作用
- javascript - 我为带有 csp 和烧瓶的内联 js 实现 nonce 有什么问题?
- python - Pandas:如何用其他列上的数学条件替换一个值?