Hi, and thank you in advance to anyone who can help me with the following …
I have a very simple menu bar that consists of four menu items, each separated by a black divider to the right of each item. The problem is I’d like to get rid of the last divider only. I’ve read to add a class to the last item and then remove the right divider that way, but I can’t seem to make that work.
Here’s an example of what I mean …
Link 1 | Link 2 | Link 3 | Link 4 |
It’s the divider after Link 4 that I’d like to get rid of.
My CSS looks like this
#navMenu li {
position: relative;
margin: 0px;
float: left;
list-style-type: none;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
border-right-width: 1px;
border-right-style: solid;
border-right-color: #000000;
}
Thank you.
Add a class to the last menu item only (to act as a hook for the CSS):
<li class="last">
Then create a new CSS rule for that li only
#navMenu li.last {
position: relative;
margin: 0px;
float: left;
list-style-type: none;
padding-top: 0px;
padding-right: 0px;
padding-bottom: 0px;
padding-left: 0px;
border-right: none;
}
You can also do this quite nicely with the CSS nth-last-child pseudo-selector. No HTML required.
#navMenu li {
position: relative;
margin: 0;
padding:0;
float: left;
list-style-type: none;
border-right: 1px solid #000;
}
/**no border on last list item**/
#navMenu li:nth-last-child(1) {
border-right:none;
}
Nancy O.
North America
Europe, Middle East and Africa
Asia Pacific