CSS - nth-child()示例

Bst*_*der 2 html css css-selectors css3

给出下面的示例,每行需要有三个文本列,即三个句子,其中中间的列也需要有一个background-color.是否可以使用nth-child() 选择器执行此操作?

p {
  display: inline-block;
  width: 30%;
}

p:nth-child(2n+0) {
  background: red;
}
Run Code Online (Sandbox Code Playgroud)
<p>The first paragraph.</p>
<p>The second paragraph.</p>
<p>The third paragraph.</p>
<p>The fourth paragraph.</p>
<p>The fifth paragraph.</p>
<p>The sixth paragraph.</p>
<p>The seventh paragraph.</p>
<p>The eight paragraph.</p>
<p>The ninth paragraph.</p>
Run Code Online (Sandbox Code Playgroud)

ne1*_*10s 5

你可以用

p:nth-child(3n+2) {
  background: red;
}
Run Code Online (Sandbox Code Playgroud)