我想知道如何在实际范围内选择第一个孩子,让我举个例子,这样你就可以正确理解我的问题:
HTML:
<div class="comment commentCompany">
<div class="commentTop"></div>
<div class="commentMiddle">
Text of comment level two comment.
<div class="comment">
<div class="commentTop"></div>
<div class="commentMiddle">
Text of comment level three.
</div>
<div class="commentBottom"></div>
</div>
</div>
<div class="commentBottom"></div>
</div>
我首先想到的 CSS 会影响 commentCompany 类中的类 commentTop、commentMiddle、commentBottom 但仅在直接范围内是这样的:
.commentCompany .commentTop:first-child{/*affect company's .commentTop*/}
.commentCompany .commentMiddle:first-child{/*affect company's .commentMiddle*/}
.commentCompany .commentBottom:first-child{/*affect company's .commentBottom*/}
但是有两个问题: :first-child 更像是第一类元素的类型(不是真正的类的第一个子元素)(必须使用第 n 个子元素),主要问题:它也影响嵌套注释 - 其中不是公司的评论 -那么如何只获得commentCompany的直接范围?
如果有任何区别,我想知道 CSS2 && CSS3 解决方案。谢谢!:)