gpt4 book ai didi

html - CSS - nth-child() 例子

转载 作者:太空宇宙 更新时间:2023-11-04 14:09:32 25 4
gpt4 key购买 nike

在下面的示例中,每一行需要有三个文本列,即三个句子,其中中间的句子也需要有一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com