views:

121

answers:

3

Given

<ul class="menu">
<li> <!-- layer1 -->
    <a href="/gbcweb/index.php?option=com_content&amp;view=article&amp;id=19&amp;Itemid=27">
        <span>sub menu</span>
    </a>
    <ul>
        <li><!-- layer2 -->
            <a href="/gbcweb/index.php?option=com_content&amp;view=article&amp;id=22&amp;Itemid=34">
                <span>sub menu1</span>
            </a>
            <ul>
                <li><!-- layer3 -->
                    <a href="/gbcweb/index.php?option=com_content&amp;view=article&amp;id=22&amp;Itemid=34">
                        <span>sub menu2</span>
                    </a>
                    <!-- Continue layering -->
                </li>
            </ul>
        </li>
    </ul>
</li><ul>

How do I select all the from layer 2 onwards?And set a background image to all sub menu.

+2  A: 
ul li li {
   background-image: url(smotheing.jpg);
}
Jakub Hampl
A: 

Try .menu ul li{}

edl
A: 

There is also the > operator that is meant to select only the immediate children of the element before it.

For instance, if I had a multiple-level list like you do, I could write the following:

ul li {
    /* normal list styles */
}

ul > li {
    /* style to apply ONLY to first-level <li> tags */
}

ul > li > ul > li {
    /* style to apply ONLY to second-level <li> tags */
}

ul > li li {
    /* style to apply to everything BELOW the first level */
}
amphetamachine
ul > li will obviously select any li (except those in an ordered list).menu > li would do what you intend to do, as well as .menu>li>li and .menu>li>li>li for resp. 2nd and 3rd level. .menu>li>li li for 3rd+ level and .menu>li>li>li li for 4th+ level
Felipe Alsacreations
I think that (according to quick test at: http://jsbin.com/osaqi) `ul > li > li` doesn't do what you think it does, but `ul > li > ul > li` does.
David Thomas
Oooops, that's right. `li li` is an optimization over `li ul li` (with a lower priority though), `li > li` is an error.
Felipe Alsacreations
Yeah, sorry forgot that a bare `li` inside of a `li` is an HTML error.
amphetamachine