JSFiddle - React, Tailwind, and code Playground
HTML
<div id="nav"></div>
<button id="button">Toggle</button>
CSS
body {
margin: 0;
}
div {
position: fixed;
left: -100%;
top: 0;
bottom: 0;
width: 100%;
background: #f00;
transition: left .2s;
}
.open {
left: 0;
}
button {
position: relative;
z-index: 1;
}
@media (min-width: 768px) {
div {
position: static;
height: 50px;
}
}
JavaScript
button.addEventListener('click', () => {
nav.classList.toggle('open')
})