Select this but not that


I have a menu like:

        <li><a href="index.php">Home</a></li>
        <li><a href="forum.php">Community</a>
                <li><a href="forum.php">Forum</a></li>
        <li><a>Account Management</a></li>

I'm using the following to style the 'Community' link:

nav ul li:nth-child(2) a 

But that also styles the 'Forum' link which I don't want.

Problem courtesy of: Kryptix


You will need to add some child selectors, otherwise your selector will ignore nesting levels and always select any a elements that's nested within your second li:

nav > ul > li:nth-child(2) > a

See this other answer for an illustration of the child selector.

Solution courtesy of: BoltClock


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.