在以下标记中,我想申请CSS只有与类.box
,其中紧跟在.wrap之后。如果它在<p>
或.wrap
以外的任何其他类之后,我不想选择它。选择第一课后,在一个特定的类
<div class="wrap">
<div class="box">Apply style to this box</div>
<p>random</p>
<div class="box">Do not apply style to this box</div>
</div>
我试图看看邻接的兄弟选择器,但似乎并没有在这种情况下工作。
.wrap + .box{
background: red;
}
的jsfiddle:http://jsfiddle.net/8fjuz7sm/
我不能使用:first-child
,因为它只能出现一次了。