Dropdown Menu

Create a smooth dropdown menu by HTML and CSS

How to create a drop-down menu for your website by using HTML and CSS coding. The drop-down menu will appear when someone hovers over its menu item; once the drop-down menu appears, the user will be able to click one of the menu item link in it to visit the individual page.

 

Step one – HTML Markup:

<div class="mainmenu">
	<ul id="navigation">
		<li class="active"><a href="#">Home</a></li>
		<li><a href="#">About</a></li>
		<li><a href="#">Pages <i class="fa fa-long-arrow-down"></i></a>
			<ul>
				<li><a href="#">Single Blog</a></li>
				<li><a href="#">Single Service</a></li>
				<li><a href="#">Single Project</a></li>
				<li><a href="#">404 Not Found</a></li>
			</ul>
		</li>

		<li><a href="#">Services</a></li>
		<li><a href="#">Projects </a>
			
		</li>
		<li><a href="#">Gallery</a></li>
		<li><a href="#">Blog</a></li>
		<li><a href="#">Contact</a></li>
	</ul>
</div>

 

Step two – CSS:

.mainmenu ul {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: right;
}
.mainmenu ul li {
  display: inline-block;
  position: relative;
}
.mainmenu ul li a {
  display: block;
  color: #222;
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
  padding: 30px 20px;
    transition: .3s;
    -webkit-transition: all 0.3s ease 0s;
}
.mainmenu ul li a:before {
    position: absolute;
    bottom: 0;
    content: "";
    width: 100%;
    height: 3px;
    background: #ffc527;
    left: 0;
    opacity: 0;
    transition: .3s;
    -webkit-transition: all 0.3s ease 0s;
    visibility: hidden;
}
.mainmenu ul li:hover > a:before, .mainmenu ul li.active > a:before {
    opacity: 1;
    visibility: visible;
}
.mainmenu ul li:hover > a, .mainmenu ul li.active > a {
  background: #f4f4f4;
  text-decoration: none;
    color: #ffc527;
}
.mainmenu li ul {
    background: #fff none repeat scroll 0 0;
    left: 0;
    opacity: 0;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";
    position: absolute;
    text-align: left;
    top: 108px;
    -webkit-transition: all 0.3s ease 0s;
    transition: all 0.3s ease 0s;
    visibility: hidden;
    width: 200px;
    z-index: -1;
}
.mainmenu li ul li {
    display: block;
}
.mainmenu li ul li a {
    padding-bottom: 5px;
    padding-top: 5px;
    text-transform: none;
}
.mainmenu li:hover ul {
    opacity: 1;
    -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=100)";
    visibility: visible;
    z-index: 99;
    top: 88px;
}