Reputation: 129
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.
Upvotes: 0
Views: 135
Reputation: 724452
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.
Upvotes: 2