JSFiddle - React, Tailwind, and code Playground

by luka kupunia

HTML

<div id="test">
  <div id="burger">
    <span></span>
    <span></span>
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>

CSS

#burger {
  margin: 0 20px;
  height: 28px;
  width: 40px;
  position: relative;
  margin-top: 3px;
  cursor: pointer;
}

#burger span {
  display: block;
  position: absolute;
  right: 0;
  border-radius: 12px;
  height: 6px;
  background: #4D4E54;
  transform-origin: right;
  transform: scaleX(0);
  transition: 1s;
}

#burger span {
  background: #EBEBEB;
}

#burger span {
  transform: scaleX(1);
}

#burger span {
  background: #4D4E54 !important;
}

#burger span:nth-child(1) {
  width: 100%;
  top: 0;
  min-width: 40px;
}

#burger span:nth-child(2) {
  width: 100%;
  top: 11px;
  min-width: 40px;
  transition-delay: 0s;
}

#burger span:nth-child(3) {
  width: 27px;
  bottom: 0;
  transition-delay: 0s;
}

#burger span:nth-child(4) {
  height: 6px;
  top: 0;
  width: 100%;
  transform-origin: top left;
  left: 4px;
  transform: rotate(45deg) scaleX(0);
}

#burger span:nth-child(5) {
  height: 6px;
  top: 0;
  width: 100%;
  transform-origin: top right;
  right: 4px;
  transform: rotate(-45deg) scaleX(0);
}

.burger-opened #burger span:nth-child(1) {
  transform: scaleX(0);
}

.burger-opened #burger span:nth-child(2) {
  transform: scaleX(0);
}

.burger-opened #burger span:nth-child(4) {
  transform: rotate(45deg) scaleX(1);
}

.burger-opened #burger span:nth-child(5) {
  transform: rotate(-45deg) scaleX(1);
}

JavaScript

document.querySelector('#burger').addEventListener('click',function(){
	document.querySelector('#test').classList.toggle('burger-opened')
})