css - 如何简化表格的CSS样式

标签 css

我有一个要改进的 CSS 代码。实际上这段代码是从 Chrome 样式检查器中复制粘贴的。但我坚持尝试使用嵌套将其简化为一条规则以获得“干净”的样式:

.table > thead > tr > th, .table > thead > tr > td,
.table > tbody > tr > th, .table > tbody > tr > td,
.table > tfoot > tr > th, .table > tfoot > tr > td {
  border-top: 1px solid #000;
}

有没有办法让它更简单?

最佳答案

在表中我们找到<th><td><thead> , <tbody><tfoot>在上面的 css 中,所有的东西都是有针对性的,所以为什么不简单地使用它

.table th, .table td{
  border-top: 1px solid #000;
}

这也将针对所有 <th><td>在表格中。

关于css - 如何简化表格的CSS样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37459767/

相关文章:

javascript - 将给定的分钟值从 api 转换为正确的小时格式并显示在 UI 上并以 api 分钟格式发布相同的小时数

css3 指针事件不在 child 身上?

css - 将文本放在元素的底部

javascript - 基于div更改滚动上的字体颜色

html - CSS Fixed header-是否需要两个位置?

css - 无法使用 material-ui 更改或删除灰色背景

css - 菜单在 Internet Explorer 9 中不可见

css - 在背景图像中使用负边距显示元素符号的问题(IE6 和 7)

css - translate3d改变div大小时为什么会出现边距?

javascript - onclick 在第一次点击时不起作用