<div class="menu-btn">
<div></div>
</div>
.menu-btn {
width: 60px;
height: 60px;
background: #8d99ae;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.5s ease;
div {
width: 80%;
height: 3px;
border-radius: 2px;
background: #fff;
position: relative;
transition: all 0.5s ease;
&::before,
&::after {
content: "";
position: absolute;
width: 50%;
height: 3px;
border-radius: 2px;
background: #fff;
transition: all 0.5s ease;
transform-origin: center;
}
&::before {
top: -15px;
}
&::after {
top: 15px;
right: 0;
}
}
}
.close {
background: #d1345b;
div {
transform: rotate(225deg);
&::before {
transform: rotate(90deg);
width: 100%;
top: 0px;
}
&::after {
opacity: 0
}
}
}
body {
padding: 0;
margin: 0;
background: #2b2d42;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
View Compiled
const menuBtn = document.querySelector(".menu-btn");
const addRemoveClass = (className) => {
if(menuBtn.classList.contains(className)){
menuBtn.classList.remove(className);
} else {
menuBtn.classList.add(className);
}
};
menuBtn.addEventListener("click", () => addRemoveClass('close'));
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.