DROP DOWN MENU

I want us to learn of how to create a drop down menu using CSS and HTM

<!DOCTYPE html>

<html lang=”en”>

<head>

<meta charset=”utf-8″>

<title>Show Hide Dropdown Using CSS</title>

<style>

ul{

padding: 0;

list-style: none;

background: #f2f2f2;

}

ul li{

display: inline-block;

position: relative;

line-height: 21px;

text-align: left;

}

ul li a{

display: block;

padding: 8px 25px;

color: #333;

text-decoration: none;

}

ul li a:hover{

color: #fff;

background: #939393;

}

ul li ul.dropdown{

min-width: 100%; /* Set width of the dropdown */

background: #f2f2f2;

display: none;

position: absolute;

z-index: 999;

left: 0;

}

ul li:hover ul.dropdown{

display: block;/* Display the dropdown */

}

ul li ul.dropdown li{

display: block;

}

</style>

</head>

<body>

<ul>

<li><a href=”#”>Home</a></li>

<li><a href=”#”>About</a></li>

<li>

<a href=”#”>Products &#9662;</a>

<ul class=”dropdown”>

<li><a href=”#”>Laptops</a></li>

<li><a href=”#”>Monitors</a></li>

<li><a href=”#”>Printers</a></li>

</ul>

</li>

<li><a href=”#”>Contact</a></li>

</ul>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu sem tempor, varius quam at, luctus dui. Mauris magna metus, dapibus nec turpis vel, semper malesuada ante. Vestibulum id metus ac nisl bibendum scelerisque non non purus. Suspendisse varius nibh non aliquet sagittis. In tincidunt orci sit amet elementum vestibulum. Vivamus fermentum in arcu in aliquam. Quisque aliquam porta odio in fringilla. Vivamus nisl leo, blandit at bibendum eu, tristique eget risus. Integer aliquet quam ut elit suscipit, id interdum neque porttitor. Integer faucibus ligula.</p>

</body>

Below is another way of creating drop down menu using HTML and CSS

<!DOCTYPE html>
<html>
<head>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}

li {
float: left;
}

li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}

li.dropdown {
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.dropdown-content a:hover {background-color: #f1f1f1;}

.dropdown:hover .dropdown-content {
display: block;
}
</style>
</head>
<body>

<ul>
<li><a href=”#home”>Home</a></li>
<li><a href=”#news”>News</a></li>
<li class=”dropdown”>
<a href=”javascript:void(0)” class=”dropbtn”>Dropdown</a>
<div class=”dropdown-content”>
<a href=”#”>Link 1</a>
<a href=”#”>Link 2</a>
<a href=”#”>Link 3</a>
</div>
</li>
</ul>

<h3>Dropdown Menu inside a Navigation Bar</h3>
<p>Hover over the “Dropdown” link to see the dropdown menu.</p>

</body>
</html>

 

 

 

Related posts