Last active
January 30, 2019 18:19
-
-
Save SpookNyan/326f0bf907fc8650a645c4269b5b0cd6 to your computer and use it in GitHub Desktop.
CSS Animated Hamburger Icon - Sass
This file contains hidden or 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
<div class="entire-menu"> | |
<input type="checkbox" id="change-hamburguer" /> | |
<a class="hamburguer" href="#"> | |
<span></span> | |
<label for="change-hamburguer"></label> | |
</a> | |
<div class="menu"> | |
<a href="#">Item</a> | |
<a href="#">Item</a> | |
<a href="#">Item</a> | |
<a href="#">Item</a> | |
<a href="#">Item</a> | |
<p><a href="#">Item</a></p> | |
</div> | |
</div> |
This file contains hidden or 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
$button-size: 20px; | |
$button-color: #000; | |
@function calc-line-height($n) { | |
@return $n / 5; | |
} | |
@mixin css3-rotation($n){ | |
-ms-transform:rotate($n); | |
-webkit-transform:rotate($n); | |
transform: rotate($n); | |
} | |
*{ | |
margin: 0; | |
padding: 0; | |
box-sizing: border-box; | |
} | |
body{ | |
background: url(http://www.tutsup.com/wp-content/uploads/2014/07/01.png) no-repeat; | |
background-size: cover; | |
} | |
.entire-menu{ | |
position: absolute; | |
padding: 20px; | |
width: 100%; | |
} | |
.hamburguer{ | |
width: $button-size; | |
height: $button-size; | |
display: block; | |
position: relative; | |
background: none; | |
margin: 0 0 10px 0; | |
&:after, &:before, span, label{ | |
content: ' '; | |
display: block; | |
width: 100%; | |
height: calc-line-height( $button-size ); | |
background: $button-color; | |
left:0; | |
position: absolute; | |
-webkit-transition: all 300ms ease-in-out; | |
transition: all 300ms ease-in-out; | |
} | |
&:before{ | |
top: 0; | |
} | |
&:after{ | |
bottom: 0; | |
} | |
&:focus{ | |
outline: none; | |
} | |
label{ | |
width: 100%; | |
height: 100%; | |
background: none; | |
cursor: pointer; | |
z-index: 1000; | |
} | |
span{ | |
top: calc-line-height( $button-size ) * 2; | |
} | |
} | |
#change-hamburguer{ | |
display:none; | |
&:checked ~ .hamburguer:before, &:checked ~ .hamburguer:after { | |
top: $button-size / 2; | |
margin-top: -10%; | |
} | |
&:checked ~ .hamburguer:before{ | |
@include css3-rotation(-45deg); | |
} | |
&:checked ~ .hamburguer:after{ | |
@include css3-rotation(45deg); | |
} | |
&:checked ~ .hamburguer span{ | |
opacity: 0; | |
} | |
&:checked ~ .menu{ | |
max-height: 200px; | |
} | |
} | |
.menu{ | |
max-height: 0; | |
height: auto; | |
background: #000; | |
-webkit-transition: all 300ms ease-in-out; | |
transition: all 300ms ease-in-out; | |
overflow: hidden; | |
font-family: sans-serif; | |
font-weight: 400; | |
font-size: 13px ; | |
width: 50%; | |
a { | |
text-decoration: none; | |
color: #fff; | |
padding: 5px 10px; | |
display: block; | |
text-transform: uppercase; | |
border-left: 5px solid #000; | |
&:hover{ | |
border-left: 5px solid #e57373; | |
color: #e57373; | |
background: #222; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment