html - 如何为表格中特定数量的行着色?

标签 html css css-selectors

<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 条灰色线等等...

最佳答案

你可以尝试这样的事情:

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

关于html - 如何为表格中特定数量的行着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49832188/

相关文章:

css - :first-child pseudo selector not targeting element

javascript - Skrollr:褪色图像跳到 z-index 的顶部

html - 使用页脚和侧边栏创建 100vh 页面时遇到问题

html - smoothstate.js 是否不适用于不同的背景图像?

html - 如何在输入旁边的文本标签上应用CSS?

html - 如何只定位td右上角的部分内容?

css - :active css selector not working for IE8 and IE9

java - 使用 selenium 删除/更改特定元素类属性值

html - 在 CSS list-style-image 中将图像显示在文本的左侧,是否可以将图像移动到文本的右侧?

css - 如何在 CSS 中添加文本高度