body
.hamburger
.hamburger-button
.icon-opened
.bar
.bar
.bar
.hamburger-button.hamburger-button-back
.icon-closed
.bar
.bar
View Compiled
body {
background: linear-gradient(to right, #8e9eab, #eef2f3);
display: flex;
align-items: center;
align-content: center;
height: 100vh;
width: 100vw;
text-align: center;
margin: 0;
}
.hamburger {
margin: 0 auto;
width: 6rem;
height: 6rem;
transition: all 300ms ease-in;
transform-style: preserve-3d;
&-button {
border-radius: 100px;
display: inline-block;
cursor: pointer;
background: linear-gradient(to right, #485563, #29323c);
// the padding along with the inner wrap adds up to 6rem*6rem circle
padding: 1.85rem 1.5rem;
position: absolute;
top: 0;
left: 0;
backface-visibility: hidden;
&-back {
transform: rotateY(180deg);
}
}
.icon-opened {
height: 2.3rem;
width: 3rem;
position: relative;
.bar {
border-bottom: 0.33rem solid white;
position: absolute;
display: block;
width: 100%;
&:first-of-type {
top: 0;
}
&:nth-of-type(2) {
top: 1rem;
}
&:nth-of-type(3) {
top: 2rem;
}
}
}
.icon-closed {
height: 2.3rem;
width: 3rem;
position: relative;
backface-visibility: hidden;
.bar {
border-bottom: 0.33rem solid white;
position: absolute;
display: block;
width: 100%;
&:first-of-type {
top: 1em;
transform: rotate(45deg);
}
&:nth-of-type(2) {
top: 1em;
transform: rotate(-45deg);
}
}
}
}
.hamburger.opened {
transform: rotateY(180deg);
}
View Compiled
const hamburger = document.querySelector('.hamburger');
hamburger.addEventListener('click', function(){
hamburger.classList.toggle('opened');
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.