我有一个动态表,在这个 jsfiddle 链接中是其中一部分的示例
我想添加一个适当的 CSS 来按日期列交替颜色,我正在寻找像这样的 CSS:
tr:nth-child(4n) td { }
但我不知道我应该更改为日期下的整个列单元格着色的 4n 迭代。
哪种方法最好?
最佳答案
您的代码将影响每四行中的所有单元格。
您想要的是标题行每隔一列交替颜色,数据行每隔 6 列交替第 4、5 和 6 列。
thead tr th:nth-child(2n) {
background-color: #ccf;
}
tbody tr th:nth-child(6n + 4),
tbody tr th:nth-child(6n + 5),
tbody tr th:nth-child(6n + 6),
tbody tr td:nth-child(6n + 4),
tbody tr td:nth-child(6n + 5),
tbody tr td:nth-child(6n + 6) {
background-color: #ccf;
}
关于jquery - 表格交替 n 列 CSS 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21638496/