HTML
Copy Copied!
<div class="container">
<!-- This checkbox will give us the toggle behavior, it will be hidden, but functional -->
<input id="toggle" type="checkbox">
<!-- IMPORTANT: Any element that we want to modify when the checkbox state changes go here, being "sibling" of the checkbox element -->
<!-- This label is tied to the checkbox, and it will contain the toggle "buttons" -->
<label class="toggle-container" for="toggle">
<!-- If menu is open, it will be the "X" icon, otherwise just a clickable area behind the hamburger menu icon -->
<span class="button button-toggle"></span>
</label>
<!-- The nav menu -->
<nav class="nav">
<a class="nav-item" href="">Menu 1</a>
<a class="nav-item" href="">Menu 2</a>
<a class="nav-item" href="">Menu 3</a>
<a class="nav-item" href="">Menu 4</a>
</nav>
<section class="content">
<h1>Content</h1>
<div class="text">
<span></span><span></span>
</div>
<div class="square"></div>
<div class="square"></div>
<div class="square"></div>
</section>
</div>
CSS
Copy Copied!
.container {
position: relative;
margin: 35px auto 0;
width: 300px;
height: 534px;
background-color: #F5F5F5;
overflow: hidden;
}
/* Toggle functionality */
#toggle {
display: none;
}
#toggle:focus ~ .toggle-container .button-toggle {
box-shadow: 0 0 0 8px rgba(0, 0, 0, 0.1), inset 0 0 0 20px rgba(0, 0, 0, 0.1);
}
#toggle:checked ~ .toggle-container .button-toggle {
box-shadow: 0 0 0 556px rgba(0, 0, 0, 0.1), inset 0 0 0 20px rgba(0, 0, 0, 0.1);
}
#toggle:checked ~ .toggle-container .button-toggle:hover {
box-shadow: 0 0 0 550px rgba(0, 0, 0, 0.1), inset 0 0 0 20px rgba(0, 0, 0, 0.1), 0 0 0 8px rgba(0, 0, 0, 0.1), inset 0 0 0 20px rgba(0, 0, 0, 0.1);
}
#toggle:checked ~ .toggle-container .button-toggle:before {
-webkit-transform: translateY(-50%) rotate(45deg) scale(1);
transform: translateY(-50%) rotate(45deg) scale(1);
}
#toggle:checked ~ .toggle-container .button-toggle:after {
-webkit-transform: translateY(-50%) rotate(-45deg) scale(1);
transform: translateY(-50%) rotate(-45deg) scale(1);
}
#toggle:checked:focus ~ .toggle-container .button-toggle {
box-shadow: 0 0 0 550px rgba(0, 0, 0, 0.1), inset 0 0 0 20px rgba(0, 0, 0, 0.1), 0 0 0 8px rgba(0, 0, 0, 0.1), inset 0 0 0 20px rgba(0, 0, 0, 0.1);
}
#toggle:checked ~ .nav {
margin-bottom: 100px;
pointer-events: auto;
-webkit-transform: translate(50px, 50px);
transform: translate(50px, 50px);
}
#toggle:checked ~ .nav .nav-item {
color: #C53532;
letter-spacing: 0;
height: 40px;
line-height: 40px;
margin-top: 0;
opacity: 1;
-webkit-transform: scaleY(1);
transform: scaleY(1);
-webkit-transition: 0.5s, opacity 0.1s;
transition: 0.5s, opacity 0.1s;
}
#toggle:checked ~ .nav .nav-item:nth-child(1) {
-webkit-transition-delay: 0.15s;
transition-delay: 0.15s;
}
#toggle:checked ~ .nav .nav-item:nth-child(1):before {
-webkit-transition-delay: 0.15s;
transition-delay: 0.15s;
}
#toggle:checked ~ .nav .nav-item:nth-child(2) {
-webkit-transition-delay: 0.1s;
transition-delay: 0.1s;
}
#toggle:checked ~ .nav .nav-item:nth-child(2):before {
-webkit-transition-delay: 0.1s;
transition-delay: 0.1s;
}
#toggle:checked ~ .nav .nav-item:nth-child(3) {
-webkit-transition-delay: 0.05s;
transition-delay: 0.05s;
}
#toggle:checked ~ .nav .nav-item:nth-child(3):before {
-webkit-transition-delay: 0.05s;
transition-delay: 0.05s;
}
#toggle:checked ~ .nav .nav-item:nth-child(4) {
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
#toggle:checked ~ .nav .nav-item:nth-child(4):before {
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
#toggle:checked ~ .nav .nav-item:before {
opacity: 0;
}
#toggle:checked ~ .content {
padding-top: 30px;
background-color: rgba(0, 0, 0, 0.3);
}
/* Toggle button */
.button-toggle {
position: absolute;
display: inline-block;
width: 20px;
height: 20px;
margin: 25px;
background-color: transparent;
border: none;
cursor: pointer;
border-radius: 100%;
-webkit-transition: 0.6s;
transition: 0.6s;
}
.button-toggle:hover {
box-shadow: 0 0 0 8px rgba(0, 0, 0, 0.1), inset 0 0 0 20px rgba(0, 0, 0, 0.1);
}
.button-toggle:before, .button-toggle:after {
position: absolute;
content: '';
top: 50%;
left: 0;
width: 100%;
height: 2px;
background-color: #c53532;
border-radius: 5px;
-webkit-transition: 0.5s;
transition: 0.5s;
}
.button-toggle:before {
-webkit-transform: translateY(-50%) rotate(45deg) scale(0);
transform: translateY(-50%) rotate(45deg) scale(0);
}
.button-toggle:after {
-webkit-transform: translateY(-50%) rotate(-45deg) scale(0);
transform: translateY(-50%) rotate(-45deg) scale(0);
}
/* Menu */
.nav {
display: inline-block;
margin: 25px 25px 20px;
pointer-events: none;
-webkit-transition: 0.5s;
transition: 0.5s;
}
.nav-item {
position: relative;
display: block;
color: transparent;
font-size: 14px;
letter-spacing: -6.8px;
height: 7px;
width: 20px;
line-height: 7px;
text-transform: uppercase;
white-space: nowrap;
-webkit-transform: scaleY(0.2);
transform: scaleY(0.2);
-webkit-transition: 0.5s, opacity 1s;
transition: 0.5s, opacity 1s;
}
.nav-item:nth-child(1) {
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
.nav-item:nth-child(1):before {
-webkit-transition-delay: 0s;
transition-delay: 0s;
}
.nav-item:nth-child(2) {
-webkit-transition-delay: 0.05s;
transition-delay: 0.05s;
}
.nav-item:nth-child(2):before {
-webkit-transition-delay: 0.05s;
transition-delay: 0.05s;
}
.nav-item:nth-child(3) {
-webkit-transition-delay: 0.1s;
transition-delay: 0.1s;
}
.nav-item:nth-child(3):before {
-webkit-transition-delay: 0.1s;
transition-delay: 0.1s;
}
.nav-item:nth-child(4) {
-webkit-transition-delay: 0.15s;
transition-delay: 0.15s;
}
.nav-item:nth-child(4):before {
-webkit-transition-delay: 0.15s;
transition-delay: 0.15s;
}
.nav-item:nth-child(n + 4) {
margin-top: -7px;
opacity: 0;
}
.nav-item:before {
position: absolute;
content: '';
top: 50%;
left: 0;
width: 100%;
height: 2px;
background-color: #c53532;
-webkit-transform: translateY(-50%) scaleY(5);
transform: translateY(-50%) scaleY(5);
-webkit-transition: 0.5s;
transition: 0.5s;
}
/* Content */
.content {
position: relative;
text-align: center;
-webkit-transition: 0.5s;
transition: 0.5s;
}
.text {
margin: 15px 0 30px;
}
.text span {
display: inline-block;
height: 10px;
margin: 0 5px;
background-color: #666666;
border-radius: 5px;
}
.text span:first-child {
width: 50px;
}
.text span:last-child {
width: 80px;
}
.square {
display: inline-block;
position: relative;
width: 250px;
height: 100px;
background-color: #666666;
}