<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
#button {
position: relative;
width: 4rem;
height: 4rem;
background: #000;
cursor: pointer;
}

#button:hover {
background: rgb(0, 100, 100);
}

#icon {
position: absolute;
top: 0;
right: 1rem;
left: 1rem;
width: auto;
height: 100%;
}

/* MENU ICON */

.lines,
.lines:before,
.lines:after {
position: absolute;
display: block;
width: 100%;
left: 0;
background: #FFFFFF;
transition: 0.3s;
}

.lines {
height: 3px;
margin-top: -2px;
top: 50%;
}

.lines:before,
.lines:after {
content: '';
height: 100%;

/* Try different values here: .25rem, .5rem, .2rem, 5rem, 10rem... */
transform-origin: 5rem center;
}

.lines:before {
top: 8px;
}

.lines:after {
top: -8px;
}

/* CLOSE ICON */

.close {
transform: scale3d(0.8, 0.8, 0.8);
}

.close .lines {
background: transparent;
}

.close .lines:before,
.close .lines:after {
top: 0;
transform-origin: 50% 50%;
}

.close .lines:before {
transform: rotate3d(0, 0, 1, 45deg);
}

.close .lines:after {
transform: rotate3d(0, 0, 1, -45deg);
}
</style>

</head>
<body>
<div id="button">
<div id="icon">
<span class="lines"></span>
</div>
</div>
<script>
const button = document.getElementById('button');
const icon =  document.getElementById('icon');
button.onclick = () => icon.classList.toggle('close');
</script>
</body>
</html>

 

Яндекс.Метрика