在下面的示例中,每一行需要有三个文本列,即三个句子,其中中间的句子也需要有一个 background-color
。是否可以使用 nth-child()
选择器 来做到这一点?
p {
display: inline-block;
width: 30%;
}
p:nth-child(2n+0) {
background: red;
}
<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>
最佳答案
你可以使用
p:nth-child(3n+2) {
background: red;
}
关于html - CSS - nth-child() 例子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54177506/