开发者

Selecting child items

开发者 https://www.devze.com 2023-04-12 22:48 出处:网络
I have HTML code: <ul id=\"top_nav\"> <li > <a href=\"#\"> <span>About</span>

I have HTML code:

<ul id="top_nav">
<li >
    <a href="#">
        <span>About</span>
开发者_如何转开发    </a>
</li>
<li class="active">
    <a href="#"><span>News</span></a>
    <ul>
        <li class="active">
            <a href="#">
                <span>News1</span>
            </a>
        </li>
        <li>
            <a href="#">
                <span>News2</span>
            </a>
        </li>
    </ul>
</li>
<li>
    <a href="#">
        <span>Contacts</span>
    </a>
</li>

I need to select News1 item. I try:

#top_nav li ul li .active a span{
    color:#ff0000;
}

But still no good. You can try by yourself at http://jsfiddle.net/dCGQ2/2/

So any ideas about that ?


#top_nav li ul li.active a span

Notice no space before .active. That means that the element (li in this case) has the class active. With a space, it means a child element with class active.


You are trying to match "A list item that is a member of the active class" (li.active) but you are saying "A member of the active class that is a descendent of a list item" (li .active).

Get rid of the space.

0

精彩评论

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