Easy Hamburger Menu Animation with HTML & CSS
07/11/2020
Demo
Video Tutorial
Code
HTML
<!DOCTYPE html>
<html>
<head>
<title>Easy Hamburger Menu Animation</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="container">
<input id="nav-input" type="checkbox">
<label class="hamburger" for="nav-input"><span></span></label>
</div>
</body>
</html>
CSS
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400&display=swap');
body {
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
#container {
width: 100%;
height: 100vh;
background: #262626;
display: flex;
align-items: center;
justify-content: center;
}
#nav-input {
display: none;
}
.hamburger {
position: relative;
width: 100px;
height: 80px;
cursor: pointer;
}
.hamburger span,
.hamburger span::before,
.hamburger span::after {
content: '';
position: absolute;
width: 100%;
height: 8px;
border-radius: 5px;
background: rgba(247,245,176,1);
transition: .5s;
}
.hamburger span {
top: 45%;
}
.hamburger span::before {
top: -35px;
}
.hamburger span::after {
top: 35px;
}
#nav-input:checked ~ .hamburger span {
background: rgba(247,245,176,0);
}
#nav-input:checked ~ .hamburger span::before {
transform: translateY(35px) rotate(45deg);
}
#nav-input:checked ~ .hamburger span::after {
transform: translateY(-35px) rotate(-45deg);
}