Skip to content

Instantly share code, notes, and snippets.

@yveshema
Created January 8, 2020 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yveshema/cbdf2e85bf9e8364afb90b15e672bef9 to your computer and use it in GitHub Desktop.
Save yveshema/cbdf2e85bf9e8364afb90b15e672bef9 to your computer and use it in GitHub Desktop.
Pure CSS hamburger menu with fixed positioning
<ul class="menu">
<li><a href="#!"><i class="material-icons">menu</i></a>
<ul>
<li>Menu</li>
<li>item1</li>
<li>item2</li>
<li>item3</li>
</ul>
</li>
</ul>
/* remove default styles, margins and any padding */
.menu, .menu * {
margin:0;
padding:0;
list-style:none;
}
.menu ul {
display:none;
}
.menu ul li {
padding:0.5em 0;
border-bottom: 1px solid white;
text-align: center;
}
.menu ul li:first-child {
background: #ccc;
font-weight: bold;
}
.menu > li:focus-within ul {
display:block;
position:fixed;
top:0;
left:0;
background: teal;
width: 30%;
height: 100vh;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/material-design-icons/3.0.1/iconfont/material-icons.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment