To create a submenu, start by nesting a <ul>
inside an <li>
element.
<li>
<a href="#" >Products<span style="color:#1D8A4C">▼</span></a>
<ul class="submenu">
<li><a href="">Submenu item</a></li>
<li><a href="">Submenu item</a></li>
<li><a href="">Submenu item</a></li>
<li><a href="">Submenu item</a></li>
</ul>
</li>
Next, apply the following CSS to style the submenu correctly:
.submenu {
position: absolute; /*1*/
border-top: 15px solid transparent; /*2*/
left: -9999px; /*3*/
}
li:hover > .submenu {
left: -50px;
}
.submenu:before {
content: "";
position: absolute;
z-index: 1; /* bring in front of border */
margin-top: 5px; /*1*/
left: -9999px; /*2*/
top: -15px;
/* borders for up arrow */
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #34495e;
}
.submenu > li:first-of-type {
border-radius: 5px 5px 0 0; /*1*/
}
/*
1. bottom rounded edges on submenu
*/
.submenu > li:last-of-type {
border-radius: 0 0 5px 5px; /*1*/
}
.submenu a {
font-size: 90%; /*1*/
margin: 3px; /*2*/
border-radius: 5px;
transition: background ease .3s; /*3*/
}
/*
submenu hover styles
*/
.submenu a:hover {
background: #2AC56C;
}
.submenu li {
background:#3B3B3B;
}
#menu .active a {
background: none repeat scroll 0% 0% #2AC56C;
border-radius: 5px;
}
.submenu:before {
content: "";
position: absolute;
z-index: 1; /* bring in front of border */
margin-top: 5px; /*1*/
left: 100px; /*2*/
top: -15px;
/* borders for up arrow */
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #3B3B3B;
}
Check out this JSFiddle for an example of the coding.
For more resources on building menus using CSS, refer to the following links:
Creating a Pure CSS Dropdown Menu
Google for CSS menu tutorials