In this post i am going to tell you how to create responsive Dropdown menu using only css without any javascript and jquery. This is one of the simple method because it made by using only css, The below image shows how the responsive menu looks like and also visit demo page to live preview the result of this program.
Now a days all are createed responsive website because it fits all the screens and also the mobile user increased day by day when comparing to the desktop users. So in website the main thing is to create responsive navigation, try this below example it helps to create responsive drop down menu. I hope this post will help you.
Html Code for Responsive Dropdown Menu
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Dropdown responsive menu using only css</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<label for="responsive-button" class="responsive-button">Menu</label>
<input type="checkbox" id="responsive-button" role="button">
<nav class="san-menu">
<ul>
<li><a href="#">Menu1</a></li>
<li><a href="#">Menu2</a></li>
<li><a href="#">Menu3 <span class="san-menu-arrow">▼</span></a>
<ul>
<li><a href="#">Drop-down Menu 3.1</a></li>
<li><a href="#">Drop-down Menu 3.2</a></li>
<li><a href="#">Drop-down Menu 3.3</a></li>
</ul>
</li>
<li><a href="#">Menu4</a></li>
<li><a href="#">Menu5</a></li>
<li><a href="#">Menu6 <span class="san-menu-arrow">▼</span></a>
<ul>
<li><a href="#">Drop-down Menu 6.1</a></li>
<li><a href="#">Drop-down Menu 6.2</a></li>
<li><a href="#">Drop-down Menu 6.3</a></li>
<li><a href="#">Drop-down Menu 6.4</a></li>
</ul>
</li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
</body>
</html>
Css Code for Responsive Dropdown Menu:
html, *
{
padding:0px;
margin:0px;
}
.san-menu, .san-menu ul, .san-menu ul li, .san-menu ul li a,
.san-menu ul ul, .san-menu ul ul li, .san-menu ul ul li a {
margin: 0;
padding: 0;
border: 0;
line-height: 1;
}
.san-menu ul {
list-style-type: none;
text-align: center;
background-color: #0A7A32;
}
.san-menu ul li {
position: relative;
display: inline;
text-align: center;
}
.san-menu ul li a {
text-decoration: none;
display: inline-block;
padding: 15px 25px;
color: #ffffff;
background: #0A7A32;
}
.san-menu ul li a:hover, .san-menu ul li a:focus, .san-menu ul li a:active {
color: #ffffff;
background: #0A692C;
}
.san-menu-arrow {
font-size: 10px;
}
.san-menu ul ul {
position: absolute;
display:none;
}
.san-menu ul li:hover ul {
display:block;
}
.san-menu ul ul li {
display: block;
text-align: left;
}
.san-menu ul ul li a {
width: 100%;
min-width:200px;
padding: 20px;
white-space: nowrap;
border-bottom: 1px solid #308E52;
color: #ffffff;
background: #3CB166;
}
.san-menu ul ul li a:hover, .san-menu ul ul li a:focus, .san-menu ul ul li a:active {
color: #ffffff;
background: #0A692C;
}
.san-menu ul li a, .san-menu ul ul li, .san-menu ul li:hover, .san-menu ul ul {
-webkit-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
.responsive-button {
padding: 20px;
color: #ffffff;
font-weight: bold;
background: #105A2B;
border-bottom: 1px solid #308E52;
text-align: center;
display: none;
}
input[id=responsive-button] {
display: none;
}
input[id=responsive-button]:checked ~ .san-menu {
display: block;
}
@media screen and (max-width : 780px){
.responsive-button {
display: block;
}
.san-menu {
display: none;
}
.san-menu ul li {
display: block;
border-bottom: 1px solid #308E52;
}
.san-menu ul li, .san-menu ul li a {
width: 100%;
}
.san-menu ul ul {
position: relative;
display: none;
}
.san-menu ul li:hover ul {
display: block;
}
.san-menu ul ul li {
text-align: center;
}
}
0 Comments