我有以下内容:
<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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句