CSS - Syntax to select a class within an id

Jeremy picture Jeremy · Jul 17, 2009 · Viewed 144.7k times · Source

What is the selector syntax to select a tag within an id via the class name? For example, what do I need to select below in order to make the inner "li" turn red?

<html>
<head>
    <style type="text/css">
        #navigation li
        {
            color: green;
        }

        #navigation li .navigationLevel2
        {
            color: red;
        }
    </style>
</head>
<body>
    <ul id="navigation">
        <li>Level 1 item
            <ul class="navigationLevel2">
                <li>Level 2 item</li>
            </ul>
        </li>
    </ul>
</body>
</html>

Answer

John Sheehan picture John Sheehan · Jul 17, 2009
#navigation .navigationLevel2 li
{
    color: #f00;
}