Instantly share code, notes, and snippets.
Created
June 25, 2020 06:41
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save juliangroen/defa7d39dbf54211853bd2ec5f8b666f to your computer and use it in GitHub Desktop.
Pure CSS Mobile Menu
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
<!-- HTML --> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>Taniti</title> | |
<link rel="stylesheet" href="styles.css" /> | |
</head> | |
<body> | |
<header> | |
<div>LOGO</div> | |
</header> | |
<div class="menu-wrapper"> | |
<input type="checkbox" class="menu-toggle" /> | |
<div class="menu-icon"><div></div></div> | |
<div class="menu-content"> | |
<ul> | |
<li><a href="#">Home</a></li> | |
<li><a href="#">Longlink</a></li> | |
<li><a href="#">Reallylonglink</a></li> | |
<li><a href="#">Linkeylink</a></li> | |
<li><a href="#">Contact Us</a></li> | |
<li class="copyright">©2020 Taniti</li> | |
</ul> | |
</div> | |
</div> | |
</body> | |
</html> | |
<!-- / HTML --> | |
// SCSS // | |
* { | |
box-sizing: border-box; | |
} | |
html { | |
font-size: 16px; | |
} | |
body { | |
margin: 0; | |
padding: 0; | |
} | |
header { | |
background: slateblue; | |
position: fixed; | |
text-align: center; | |
width: 100vw; | |
div { | |
color: white; | |
font-family: sans-serif; | |
font-size: 1.5rem; | |
line-height: 1.5rem; | |
padding: 1rem; | |
} | |
} | |
.menu-wrapper { | |
position: fixed; | |
top: 0; | |
left: 0; | |
width: 100vw; | |
z-index: 1; | |
.menu-toggle { | |
position: absolute; | |
top: 0; | |
right: 0; | |
height: 1.5rem; | |
width: 1.5rem; | |
margin: 1rem; | |
padding: 0; | |
cursor: pointer; | |
opacity: 0; | |
z-index: 2; | |
&:checked { | |
+ .menu-icon { | |
div { | |
transform: rotate(45deg); | |
&:before, | |
&:after { | |
top: 0; | |
transform: rotate(-90deg); | |
} | |
} | |
} | |
~ .menu-content { | |
opacity: 1; | |
visibility: visible; | |
} | |
} | |
} | |
.menu-icon { | |
position: absolute; | |
top: 0; | |
right: 0; | |
height: 1.5rem; | |
width: 1.5rem; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
margin: 1rem; | |
padding: 0; | |
z-index: 1; | |
div { | |
position: relative; | |
background: white; | |
height: 2px; | |
width: 100%; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
transition: transform 0.4s ease; | |
&:before, | |
&:after { | |
content: ""; | |
position: absolute; | |
background: white; | |
top: -8px; | |
height: 2px; | |
width: 100%; | |
} | |
&:after { | |
top: 8px; | |
} | |
} | |
} | |
.menu-content { | |
position: fixed; | |
background: slateblue; | |
top: 3.5rem; | |
left: 0; | |
height: calc(100% - 3.5rem); | |
width: 100%; | |
overflow: hidden; | |
display: flex; | |
align-items: center; | |
justify-content: center; | |
visibility: hidden; | |
opacity: 0; | |
transition: all 0.4s ease; | |
ul { | |
padding: 0; | |
li { | |
font-family: sans-serif; | |
font-size: 2rem; | |
list-style: none; | |
padding: 1rem; | |
text-align: center; | |
} | |
} | |
a { | |
color: white; | |
text-decoration: none; | |
} | |
.copyright { | |
font-size: 0.8rem; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment