JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" id="menuExpand">Menu</a>
<ul class="menu">
<li><a href="#">Menu item 1</a></li>
<li><a href="#">Menu item 2</a></li>
<li><a href="#">Menu item 3</a></li>
<li><a href="#">Menu item 4</a></li>
<li><a href="#">Menu item 5</a></li>
</ul>
CSS
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
margin: 0;
}
.menu {
list-style: none;
}
.menu li {
display: inline-block;
}
.menu li a {
display: block;
text-decoration: none;
color: #fff;
padding: 5px;
border-radius: 3px;
background-color: rgba(0, 0, 0, 1);
border: 1px solid #fff;
}
.menu li a:hover {
color: #000;
background-color: #fff;
border: 1px solid #000;
}
#menuExpand {
display: none;
color: #fff;
background-color: #000;
text-decoration: none;
padding: 5px;
text-align: center;
}
#menuExpand:hover {
color: #000;
background-color: #fff;
border-bottom: 1px solid #000;
}
@media only screen and (max-width: 767px) {
.menu {
max-height: 0;
overflow: hidden;
width: 100%;
-webkit-transition: max-height 0.3s;
-moz-transition: max-height 0.3s;
-ms-transition: max-height 0.3s;
-o-transition: max-height 0.3s;
transition: max-height 0.3s;
}
.menu li {
display: block;
}
.menu li a {
border: none;
text-align: center;
border-radius: 0;
}
#menuExpand {
display: block;
}
.menuOpen {
max-height: 1000px;
-webkit-transition: max-height 0.5s;
-moz-transition: max-height 0.5s;
-ms-transition: max-height 0.5s;
-o-transition: max-height 0.5s;
transition: max-height 0.5s;
}
}
JavaScript
var menu, menuExpand;
menu = document.getElementsByClassName("menu")[0];
menuExpand = document.getElementById("menuExpand");
menuExpand.onclick = function (e) {
menu.classList.toggle("menuOpen");
}