How to get the first ClassB inside ClassA?
how to acheive this with CSS 1.0 (IE 6.0):
.ClassA > .ClassB
{
...
}
to get the first ClassB in开发者_开发知识库side ClassA?
There's no way to do this with a pure CSS solution that works in IE6. Your best bet is to modify the HTML and add an extra class, or an ID, to the first .ClassB
element, then select that.
.ClassA .ClassB:first-child
would match the first descendant of .ClassA that is of type .ClassB
You can match all elements and then negate other than first.
Here's an example:
.classA > .classB {
background: black;
}
.classA > .classB + .classB,
.classA > .classB + * + .classB {
background: white;
}
<div class="classA">
<p class="classB" >
aaasda
</p>
<p class="classB" >
aaasdb
</p>
<p class="other">
Other Class
</p>
<p class="classB" >
aaasdc
</p>
</div>
<br/><br/><br/>
<div class="classA">
<p class="otherFirst">
other as first child
</p>
<p class="classB" >
aaasda
</p>
<p class="classB" >
aaasdb
</p>
<p class="other">
Other Class
</p>
<p class="classB" >
aaasdc
</p>
</div>
精彩评论