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 - 在 Tailwind 中,如何将 div 的高度设置为屏幕的 80%?
- vector - 在 IDL 中绘制 3D 图中的向量
- google-api - Youtube Data API v3 配额使用应用级别
- javascript - 如何将对象数组洗牌到嵌套数组?
- java - 错误:进程“/Users/runner/work/1/s/android/gradlew”失败,退出代码为 1
- python - 新手 Z-Wave Python 读取按钮值
- reactjs - 在 React 中使用 TypeScript
- scheme - Scheme语言中的词法与动态解释器
- datagrid - 在 RTL 中使用时,在 Material-UI X-Grid 中调整列大小错误
- postgresql - 如何将项目添加到 postgress 中的本地函数数组?