I have made a few attempts at this and they ended up just getting confusing. The current HTML and CSS seems to be working fine for a simple horizontal CSS menu. I am struggling with dropping subitems off the current <li> elements.
I am trying to making them show up exactly below the current menu items with the same hovering effects as I have in place now. Any assistance would be appreciated. I am admittedly no CSS pro.
Current HTML:
<div class="MenuTop">
<ul class="Nav">
<li><a href="Home.aspx" title="Home">Home</a></li>
<li><a href="Vehicles.aspx" title="Vehicles">Vehicles</a>
<ul>
<li><a href="SubItem.aspx" title="SubOne">SubItemOne</a></li>
</ul>
</li>
<li><a href="About.aspx" title="About">About</a></li>
<li><a href="Contact.aspx" title="Contact">Contact</a></li>
<li><a href="News.aspx" title="News">News</a></li>
</ul>
</div>
Current CSS:
.MenuTop
{
width: 960px;
background-color: Black;
color: #fff;
margin: auto auto 0px auto;
padding: 5px;
height:auto;
font-family: Segoe UI, Arial;
font-weight:bold;
min-height:15px;
}
.MenuTop ul
{
float: left;
list-style: none;
margin: -5px ;
padding: 0px;
}
.MenuTop li
{
float: left;
font-size:12px;
font-family: Segoe UI, Arial;
margin: 0;
padding: 0;
}
.MenuTop a
{
background-color: Black;
color: #fff;
display: block;
float: left;
margin: 0;
padding: 4px 12px 4px 12px;
text-decoration: none;
}
.MenuTop a:hover
{
background-color: #404040;
color: #fff;
padding: 4px 12px 4px 12px;
}
You were close, but you’re forgetting about positioning your submenu items absolutely to your parent
limenu item and hiding it as well, by usingdisplay:noneand then showing it on hover, so try something like this to achieve that effect:CSS
Also, your submenu
ulis not properly closed so go ahead and close it.Ninja Edit: demo, by the way you can greatly benefit from properly targeting your menu by using the class you have given it,
.Nav, instead of its parent class of its container,.MenuTop, that way you can target your menu and your menu alone and not any other element you might place inside that container,