I have a menu like:
<nav> <ul> <li><a href="index.php">Home</a></li> <li><a href="forum.php">Community</a> <ul> <li><a href="forum.php">Forum</a></li> </ul> </li> <li><a>Account Management</a></li> </ul> </nav>
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.
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
nav > ul > li:nth-child(2) > a
See this other answer for an illustration of the child selector.
There is currently no discussion for this recipe.
This recipe can be found in it's original form on Stack Over Flow.