Reputation: 1031
I want menu and sub menu both in horizontal.This is the code i tried main menu in horizontal.When i hover the mainmenu
i want submenu
also in horizontal.
Any body know how to solve this
Any help is appreciated.
Upvotes: 2
Views: 108
Reputation: 304
Try this solution:
**HTML:**
<ul id="level-1">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li>
<a href="#">Products</a>
<ul id="level-2">
<li><a href="#">Laptops</a></li>
<li><a href="#">Monitors</a></li>
<li><a href="#">Printers</a></li>
</ul>
</li>
</ul>
**CSS:**
ul{
padding: 0;
list-style: none;
}
ul#level-1 > li{
float: left;
width: 100px;
text-align: center;
}
ul li a{
display: block;
padding: 5px 10px;
color: #333;
background: #f2f2f2;
text-decoration: none;
}
ul li a:hover{
color: #fff;
background: #939393;
}
ul li ul{
display: none;
}
ul li:hover ul{
display: inline-flex;
width: auto;/* display the dropdown */
}
ul li:hover ul#level-2 li{
float: left;
display: inline-block;
}
Upvotes: 3
Reputation: 7568
Try this: JSFIDDLE Basically, you need to use absolute positioning to take the secondary menu and position it directly below the main menu.
ul li ul li{
display: inline-block;
width: 100px;
text-align: center;
}
ul li ul li a{
display: block;
padding: 5px 10px;
color: white;
background: blue;
text-decoration: none;
}
ul li ul{
display: none;
width: 300px;
position: absolute;
left: 0;
margin-left: 8px;
}
Upvotes: 2