这个类制作了一个表格,表格的行颜色成对交替(两个灰色,两个白色,等等):
.table-striped-two-rows tbody tr:nth-child(4n+1), tbody tr:nth-child(4n+2) {
background-color: rgba(0, 0, 0, 0.05);
}
问题是它也会影响没有 class="table-striped-two-rows"
的表格。
我怎样才能将样式包含在带有类的表格中?
最佳答案
您还需要为 4n + 2
行指定祖先,以限制选择器的范围
.table-striped-two-rows tbody tr:nth-child(4n+1),
.table-striped-two-rows tbody tr:nth-child(4n+2) {
background-color: rgba(0, 0, 0, 0.05);
}
关于CSS 类在未设置的地方被拾取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57270438/