I’m applying a border-right attribute to each anchor in the markup below and I’m trying to use .last-child to remove the border from the last element of the first generation anchors only. However, my index must be off as its removing borders other than the one I want…
<div class="menu nav">
<ul class="menu">
<li class="menu-item"><a href="#">Home</a></li>
<li class="menu-item"><a href="#">Contact Us</a>
<ul class="sub-menu">
<li class="menu-item"><a href="#">Directions</a></li>
</ul>
</li>
<li class="menu-item"><a href="#">About Us</a></li>
</ul>
</div>
.menu.nav ul li a {display:block; padding:0 20px; margin:10px 0; line-height:35px; text-decoration:none; border-right:1px solid #ccc;}
.menu.nav ul li a:last-child {border:none;}
As you’ve seen, he uses an extra ul prefix, because you use the same class on two different tags, even more, on a parent and one of its children: menu.
You should avoid this type of thing and you should probably be doing this: