JSFiddle - React, Tailwind, and code Playground
by Rajat Jha
HTML
<html>
<head>
<title>Menu</title>
<link href="mymenu.css" type="text/css" rel="stylesheet">
</head>
<body>
<nav class="navigation">
<ul class="mainmenu">
<li><a href="">Home</a></li>
<li><a href="">Cloths</a>
<ul class="submenu">
<li><a href="">Men's Wear</a></li>
<li><a href="">Women's Wear</a></li>
<li><a href="">Kids Wear</a></li>
</ul>
</li>
<li><a href="">About</a></li>
<li><a href="">Products</a>
<ul class="submenu">
<li><a href="">Tops</a></li>
<li><a href="">Bottoms</a></li>
<li><a href="">Footwear</a></li>
</ul>
</li>
<li><a href="">Contact us</a></li>
</ul>
</nav>
</body>
</html>
CSS
html, body {
font-family: Arial, Helvetica, sans-serif;
font-size:15px;
}
/* define a fixed width for the entire menu */
.navigation {
width: 250px;
}
/* reset our lists to remove bullet points and padding */
.mainmenu, .submenu {
list-style: none;
padding: 0;
margin: 0;
}
/* make ALL links (main and submenu) have padding and background color */
.mainmenu a {
display: block;
background-color: red;
text-decoration: none;
padding: 15px;
color: white;
border-radius: 5px;
line-height:20px;
box-shadow: 5px 5px 5px #888888;
}
/* add hover behaviour */
.mainmenu a:hover {
background-color: lightskyblue;
}
/* when hovering over a .mainmenu item,
display the submenu inside it.
we're changing the submenu's max-height from 0 to 200px;
*/
.mainmenu li:hover .submenu {
display: block;
max-height: 250px;
cursor: auto;
}
/*
we now overwrite the background-color for .submenu links only.
CSS reads down the page, so code at the bottom will overwrite the code at the top.
*/
.submenu a {
background-color: lightgreen;
cursor: auto;
}
/* hover behaviour for links inside .submenu */
.submenu a:hover {
background-color: blue;
cursor: auto;
}
/* this is the initial state of all submenus.
we set it to max-height: 0, and hide the overflowed content.
*/
.submenu {
overflow: hidden;
max-height: 0;
-webkit-transition: all 0.5s ease-out;
box-shadow: 5px 5px 5px #888888;
cursor: auto;
}