gpt4 book ai didi

CSS - 选择除第一个以外的所有 child

转载 作者:行者123 更新时间:2023-11-28 10:46:10 28 4
gpt4 key购买 nike

我有以下内容:

<div class="chapter"> 
<p>chapter 1, paragraph 1</p>
<p>chapter 1, paragraph 2</p>
<div class="section">
<p>chapter 1, section 1, paragraph 1</p>
<p>chapter 1, section 1, paragraph 2</p>
</div>
</div>
<div class="chapter">
<p>chapter 2, paragraph 1</p>
<div class="section">
<p>chapter 2, section 1, paragraph 1</p>
<p>chapter 2, section 1, paragraph 2</p>
</div>
<div class="section">
<p>chapter 2, section 2, paragraph 1</p>
<p>chapter 2, section 2, paragraph 2</p>
</div>
</div>

使用CSS,是否可以选择所有元素<p> ,除了第一个,对于每个元素 .chapter.section ?例如,我想选择 <p>chapter 1, paragraph 2</p> , <p>chapter 1, section 1, paragraph 2</p> , <p>chapter 2, section 1, paragraph 2</p> , <p>chapter 2, section 2, paragraph 2</p> , 等等。

谢谢。

最佳答案

您应该将 :first-of-type:not 结合使用

.chapter > p:not(:first-of-type),
.section > p:not(:first-of-type){
color:#ccc
}
<div class="chapter"> 
<p>chapter 1, paragraph 1</p>
<p>chapter 1, paragraph 2</p>
<div class="section">
<p>chapter 1, section 1, paragraph 1</p>
<p>chapter 1, section 1, paragraph 2</p>
</div>
</div>
<div class="chapter">
<p>chapter 2, paragraph 1</p>
<div class="section">
<p>chapter 2, section 1, paragraph 1</p>
<p>chapter 2, section 1, paragraph 2</p>
<p>chapter 2, section 1, paragraph 3</p>
<p>chapter 2, section 1, paragraph 4</p>
</div>
<div class="section">
<p>chapter 2, section 2, paragraph 1</p>
<p>chapter 2, section 2, paragraph 2</p>
</div>
</div>

关于CSS - 选择除第一个以外的所有 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27083415/

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