<header>
<h1><a href="#">Logo here</a></h1>
<input class="menu-btn" type="checkbox" id="menu-btn" />
<label class="menu-icon" for="menu-btn">
<span class="navicon" />
</label>
<nav class='menu'>
<a class='nav-item' href="#">About Me</a>
<a class='nav-item' href="#">Blog</a>
<a class='nav-item' href="#">Contact</a>
</nav>
</header>
/* Adapted from https://codepen.io/mutedblues/pen/MmPNPG */
body {
margin: 0;
}
header {
display: flex;
width: 100%;
background-color: aliceblue;
}
header > * {
/* flex-grow: 1; */
}
header h1 {
margin-left: 1rem;
}
header a {
text-decoration: none;
}
/* "Hide" checkbox -- moves it off screen*/
#menu-btn {
position: absolute;
top: -100%;
left: -100%;
}
/* Hide hamburger for bigger screens */
.menu-icon {
visibility: hidden;
}
.menu {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 250px;
margin-right: 2rem;
}
/* Set width for mobile/smaller screen size. */
/* I set it big here so I don't have to shrink the screen so much */
/* for testing purposes */
@media screen and (max-width: 1100px) {
header {
display: grid;
grid-template-areas:
"title title hamburger"
"nav nav nav";
}
h1 {
grid-area: title;
}
.menu a {
text-decoration: none;
color: black;
}
.menu-btn {
display: none;
}
.menu-icon {
grid-area: hamburger;
cursor: pointer;
display: flex;
justify-content: flex-end;
align-items: baseline;
padding: 30px 20px 30px 0;
position: relative;
user-select: none;
visibility: visible;
}
.navicon {
background: #333;
display: block;
height: 2px;
width: 18px;
position: relative;
}
.navicon:before {
top: 5px;
}
.navicon:after {
top: -5px;
}
.navicon:before, .navicon:after {
background: #333;
display: block;
width: 100%;
height: 100%;
content: '';
position: absolute;
transition: all .2s ease-out;
}
.menu {
grid-area: nav;
max-width: unset;
max-height: 0;
transition: max-height .2s ease-out;
overflow: hidden;
margin: 0;
padding: 0;
background-color: #fff;
display: flex;
flex-direction: column;
}
.menu a {
padding: 20px 20px;
border-right: 1px solid #f4f4f4;
background-color: #eee;
width: 100%;
text-align: center;
}
.menu-btn:checked ~ .menu {
max-height: 240px;
}
.menu-btn:checked ~ .menu-icon .navicon {
background: transparent;
}
.menu-btn:checked ~ .menu-icon .navicon:before {
transform: rotate(-45deg);
}
.menu-btn:checked ~ .menu-icon .navicon:after {
transform: rotate(45deg);
}
.menu-btn:checked ~ .menu-icon .navicon:before,
.menu-btn:checked ~ .menu-icon .navicon:after {
top: 0;
}
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.