The problem is that you set a negative margin on each ul .
Just remove the gasket from the .navbar and reduce the margin to get the required spacing.
.navbar { position: relative; margin: 10px 1px; float: left; padding-left: 0px; }
You can also reduce your CSS by removing identifier tags and using the .navbar class, this will also make your code more flexible, since you do not need to add new CSS every time you want to add an item to the menu:
.navbar { position: relative; margin: 10px 1px; float: left; padding-left: 0px; } .navbar li { list-style: none; overflow: hidden; } .navbar li a { display: block; padding: 3px 8px; background-color: #00AA63; color: #fff; text-decoration: none; } .navbar li ul { color: #fff; display: none; width: 10em; } .navbar li:hover ul { display: block; position: absolute; margin: 0; padding: 0; } .navbar li:hover li { float: none; } .navbar li:hover li a { background-color: #00AA63; color: #fff; border-bottom: 1px solid #fff; color: #fff; } .navbar li li a:hover { color: #fff; background-color: #33BB96; }
HTML:
<ul class="navbar"> <li><a href="#">other electives</a> <ul class="navbar"> <li><a href="#">Subitem One</a></li> <li><a href="#">Second Subitem</a></li> <li><a href="#">Numero Tres</a></li></ul> </li> </ul> <ul class="navbar"> <li><a href="#">other electivesother electives</a> <ul class="navbar"> <li><a href="#">Subitem One</a></li> <li><a href="#">Second Subitem</a></li> <li><a href="#">Numero Tres</a></li></ul> </li> </ul> <ul class="navbar"> <li><a href="#">other electives</a> <ul class="navbar"> <li><a href="#">Subitem One</a></li> <li><a href="#">Second Subitem</a></li> <li><a href="#">Numero Tres</a></li></ul> </li> </ul>
See http://jsfiddle.net/georeith/CLVwv/2/ for a working solution.
George Reith
source share