css - 第 n 个 child 交替 2 行

标签 css css-selectors

<分区>

我想使用 CSS3 的 nth-child 选择器在两行厚的背景颜色之间交替,而不是使用 nth-child(odd) 时通常的一行。

The "Result" section of this jsFiddle illustrates what I want.

所以我们会有一张 table :

ROW 1: Blue
ROW 2: Blue
ROW 3: Red
ROW 4: Red
ROW 5: Blue
ROW 6: Blue

最佳答案

你可以使用这个:

tr {
    background: blue;
}

tr:nth-child(4n+1), tr:nth-child(4n+2) {
    background: red;
}

n 将从 0 开始计数。

DEMO

关于css - 第 n 个 child 交替 2 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22994062/

相关文章:

html - 如何使 SVG 完全响应。

html - 如何在Div后台添加元素目录下的Video

css - 使用 :nth-child to loop through children LI elements

css - 为什么这个li :last-child not work?

html - 使用 CSS 在嵌套 div 上重复一组颜色

javascript - 使用 jQuery 为悬停时的 SVG 颜色和缩放设置动画

html - 使图像适合表格单元格

css - Kindle Fire 8.9 HDX 媒体查询

java - 将 XPath 转换为 CSS 选择器

html - 计算选择器的特异性(CSS)