Reputation: 1471
I'm adding a separator "|" to every menu item using the :after
selector. This adds it to the last element as well. I've been trying to remove that using the :last-child
selector and it isn't working.
I'll list my code below and also provide a jsfiddle link.
HTML:
<nav id="nav_bar">
<div>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Company Profile</a></li>
<li><a href="#">Contact Us</a></li>
</ul>
</div>
</nav>
CSS:
#nav_bar {
background-color: #debb23;
height: 45px;
}
#nav_bar ul{
list-style-type: none;
}
#nav_bar ul li{
display: inline-block;
margin: 10px 0;
}
#nav_bar ul li a{
color: #ffffff;
text-decoration: none;
padding: 0 15px;
}
#nav_bar ul li:after{
content: "|";
color: #ffffff;
}
#nav_bar ul li:last-child {
content: none;
}
Here's the jsfiddle link, http://jsfiddle.net/e3x369k0/
I appreciate any help.
Upvotes: 1
Views: 116
Reputation: 384
Try This and I've been using this technique in years :)
#nav_bar ul li{
border-right:1px solid black;
}
#nav_bar ul li:last-child{
border-right: 1px solid tranparent;
}
Upvotes: 0
Reputation: 33531
You're missing the :after
in the last CSS rule. Should be like this: #nav_bar ul li:last-child:after
Upvotes: 1
Reputation: 4435
You are targeting the last li element's content not its :after
pseudo element's content.
Change your selector from:
#nav_bar ul li:last-child {
content: none;
}
to
#nav_bar ul li:last-child:after {
content: none;
}
Live example: http://jsfiddle.net/5x55emaf/
Upvotes: 2