How to create dropdown menu with html and css

 How to create dropdown menu with html and css





HTML:-

<ul class="menu">
<li><a href="#"> Menu Item </a></li>
<li><a href="#"> Menu Item </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>
<li><a href="#"> Submenu Item</a></li>
<li><a href="#"> Submenu Item</a></li>
</ul>
</li>
<li><a href="#"> Menu Item </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>
<li><a href="#"> Submenu Item </a></li>
<li><a href="#"> Submenu Item </a></li>
</ul>
</li>
<li><a href="#"> Menu Item </a></li>
<li><a href="#"> Menu Item </a></li>
</ul>


CSS:-

body {
background: #262626;
}
.menu, .submenu {
margin: 0;
padding: 0;
list-style: none;
}
.menu {
margin: 50px auto;
width: 800px;
width: fit-content;
}
.menu > li {
background-color: #4D51D4;
float: left;
position: relative;
transform: skewX(25deg);
transition: 0.5s;
border-left: 1px solid #363BDC;
}
.menu a {
display: block;
color: #fff;
text-transform: uppercase;
text-decoration: none;
font-family: Arial, Helvetica;
font-size: 14px;
}
.menu li:hover {
background: #e74c3c;
box-shadow: 0 0 15px 0 #e74c3c;
border-left-color: #e74c3c;
}
.menu > li > a {
transform: skewX(-25deg);
padding: 1em 2em;
}
.submenu {
position: absolute;
width: 200px;
left: 50%;
margin-left: -100px;
transform: skewX(-25deg);
transform-origin: left top;
}
.submenu li {
background-color: #4D51D4;
position: relative;
overflow: hidden;
}
.submenu > li > a {
padding: 1em 2em;
}
.submenu >li::after {
content: "";
position: absolute;
top:-125%;
width: 100%;
height: 100%;
box-shadow: 0 0 50px rgba(0, 0, 0, .9);
}
.submenu > li:nth-child(odd) {
transform: skewX(-25deg) translateX(0);
}
.submenu > li:nth-child(odd) > a {
transform: skewX(25deg);
}
.submenu > li:nth-child(odd)::after {
right: -50%;
transform: skewX(-25deg) rotate(3deg);
}
.submenu > li:nth-child(even) {
transform: skewX(25deg) translateX(0);
}
.submenu > li:nth-child(even) > a {
transform: skewX(-25deg);
}
.submenu > li:nth-child(even)::after {
right: -50%;
transform: skewX(25deg) rotate(3deg);
}
.submenu, .submenu li {
opacity: 0;
visibility: hidden;
}
.submenu li {
transition: .2s ease-out transform;
}
.menu > li:hover .submenu, .menu > li:hover .submenu li {
opacity: 1;
visibility: visible;
}
.menu > li:hover .submenu li:nth-child(even) {
transform: skewX(25deg) translateX(15px);
}
.menu > li:hover .submenu li:nth-child(odd) {
transform: skewX(-25deg) translateX(-15px);
}





Comments :

Post a Comment