Created
January 8, 2020 09:02
-
-
Save yveshema/cbdf2e85bf9e8364afb90b15e672bef9 to your computer and use it in GitHub Desktop.
Pure CSS hamburger menu with fixed positioning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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