
如何使用 为表格每隔三行添加斑马纹样式?
要为表格中的每三行数据添加不同的背景色,可以使用以下 纯 css 解决方案:
.table {
border-collapse: collapse;
}
.table td {
border: 1px solid #ddd;
}
.table tr {
background-color: #f9f9f9;
}
.table tr:nth-child(6n + 1),
.table tr:nth-child(6n + 2),
.table tr:nth-child(6n + 3) {
background-color: #ffffff;
}
.table tr:nth-child(6n + 4),
.table tr:nth-child(6n + 5),
.table tr:nth-child(6n + 6) {
background-color: #cccccc;
}
登录后复制
要使用此样式,请将 .table 类应用于表格元素:
<table class="table">
<thead>
<tr> <th>COL 1</th> <th>COL 2</th> </tr>
</thead>
<tbody>
<!-- 表格数据 -->
</tbody>
</table>
登录后复制
这将为表格中的每三行数据添加交替的背景色。
立即学习“”;
以上就是如何使用 CSS 为表格每隔三行添加斑马纹样式?的详细内容,更多请关注米云其它相关文章!
