CSS 类在未设置的地方被拾取

标签 css

这个类制作了一个表格,表格的行颜色成对交替(两个灰色,两个白色,等等):

.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/

相关文章:

HTML文本区域定位与CSS

HTML + 调整水平对齐图像的大小

html - 居中图像边缘的链接

html - Django - 使用没有静态文件的 css 显示 html

css - 文本区域拼写检查弹窗不显示?

html - 在 flexed div 的中间垂直对齐内容

javascript - 通过点击事件选择文件夹名称

php - 基于laravel blade中的条件着色div

html - CSS 渐变 strip 问题?

html - 不使用百分比 TOP 值的固定高度 DIV