JSFiddle - React, Tailwind, and code Playground
HTML
<header>
<div class="menu-btn">
<span></span>
<span></span>
<span></span>
</div>
</header>
<div class="menu">
<nav>
<ul>
<li><a href="#">Главная</a></li>
<li><a href="#">О нас</a></li>
<li><a href="#">Услуги</a></li>
<li><a href="#">Контакты</a></li>
</ul>
</nav>
</div>
CSS
header {
display: flex;
justify-content: flex-end;
}
/* Гамбургер иконка */
.menu-btn {
width: 30px;
height: 30px;
position: relative;
z-index:2;
overflow: hidden;
}
.menu-btn span {
width: 30px;
height: 2px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #222222;
transition: all 0.5s;
}
.menu-btn span:nth-of-type(2) {
top: calc(50% - 5px);
}
.menu-btn span:nth-of-type(3) {
top: calc(50% + 5px);
}
/* Меняем гамбургер иконку, когда меню открыто */
.menu-btn.active span:nth-of-type(1) {
display: none;
}
.menu-btn.active span:nth-of-type(2) {
top: 50%;
transform: translate(-50%, 0%) rotate(45deg);
}
.menu-btn.active span:nth-of-type(3) {
top: 50%;
transform: translate(-50%, 0%) rotate(-45deg);
}
/* Меню, которое будет появляться */
.menu {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
padding: 15px;
background: #FFEFBA;
transform: translateX(-100%);
transition: transform 0.5s;
}
.menu.active {
transform: translateX(0);
}
.menu li {
list-style-type: none;
}
JavaScript
let menuBtn = document.querySelector('.menu-btn');
let menu = document.querySelector('.menu');
menuBtn.addEventListener('click', function(){
menuBtn.classList.toggle('active');
menu.classList.toggle('active');
})