Pure CSS mobile menu
Uses a checkbox trick to toggle the menu.
by Carson Evans
HTML
<nav>
<h1><a href="#">Title</a></h1>
<input type="checkbox" id="nav-toggle">
<label for="nav-toggle"></label>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
CSS
nav {
background-color: #337AB7;
position: relative;
}
nav:after {
display: table;
content: '';
clear: both;
}
nav h1 {
float: left;
margin: 0;
}
nav #nav-toggle {
display: none;
}
nav label[for='nav-toggle']:after {
float: right;
display: block;
padding: .5em;
margin: .5em;
width: 4em;
content: 'Menu';
text-align: center;
color: #fff;
border: 1px solid #fff;
border-radius: 3px;
transition: background-color .25s ease;
}
nav ul {
float: left;
display: block;
margin: 0;
padding: 0;
list-style: none;
width: 100%;
max-height: 0;
overflow: hidden;
transition: max-height .25s ease-in-out;
}
nav #nav-toggle:checked ~ ul {
max-height: 140px;
transition: max-height .25s ease-in-out;
}
nav #nav-toggle:checked ~ label:after {
content: 'Close';
background-color: #fff;
color: #337AB7;
transition: background-color .25s ease;
}
nav li {
margin: .5em 0;
}
nav a {
display: block;
padding: .5em;
text-decoration: none;
color: #fff;
}
nav a:hover,
nav a:active,
nav a:focus {
background-color: #fff;
color: #337AB7;
}