开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜