【问题标题】:How to color a specific amount of rows from a table?如何为表格中特定数量的行着色?
【发布时间】:2018-04-14 22:28:15
【问题描述】:
<style>     
    #font{
        font-size: 20px;
        color:#0000cd;
    }
    tr:nth-child(n+7) {
        background-color: #d3d3d3;
    }                  
    table {
       border-spacing: 0;
    }
</style>

如何只为特定数量的行着色? 这里只有我显示器的前 7 行是白色的,其余的是灰色的。我想要7行白色,7灰色,7白色,7灰色等等......

【问题讨论】:

  • 只需在其中的 7 个中添加一个公共类,依此类推

标签: html css css-selectors


【解决方案1】:

你可以试试这样的:

.table>span {
  height: 20px;
  width: 20px;
  display: inline-block;
  background: red;
}

.table>span:nth-child(14n + 1),
.table>span:nth-child(14n + 2),
.table>span:nth-child(14n + 3),
.table>span:nth-child(14n + 4),
.table>span:nth-child(14n + 5),
.table>span:nth-child(14n + 6),
.table>span:nth-child(14n + 7) {
  background: blue;
}
<div class="table">
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
  <span></span>
</div>

【讨论】:

  • 我很确定我可以优化选择器,但我没有找到诀窍:p
  • 我不认为它是可优化的。我可能是错的,但我很确定这是不可能的
  • @vals 是的,这也是我的想法.. 我尝试了很多方法,但最后我总是有一个复杂的选择器,只要这个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-10
  • 1970-01-01
  • 2017-03-08
  • 2019-04-29
  • 1970-01-01
相关资源
最近更新 更多