Skip to content

Instantly share code, notes, and snippets.

@ilyaviache
Created October 2, 2015 19:45
Show Gist options
  • Save ilyaviache/9d59b4c528a715ea2aee to your computer and use it in GitHub Desktop.
Save ilyaviache/9d59b4c528a715ea2aee to your computer and use it in GitHub Desktop.
simple menu trigger icon
.cd-nav-trigger {
/* navigation trigger - visible on mobile devices only */
float: right;
position: relative;
display: block;
width: 34px;
height: 44px;
margin-right: 5%;
/* hide text */
overflow: hidden;
white-space: nowrap;
color: transparent;
}
.cd-nav-trigger span, .cd-nav-trigger span::before, .cd-nav-trigger span::after {
/* hamburger icon in CSS */
position: absolute;
display: inline-block;
height: 3px;
width: 24px;
background: #ffffff;
}
.cd-nav-trigger span {
/* line in the center */
position: absolute;
top: 50%;
right: 5px;
margin-top: -2px;
-webkit-transition: background 0.2s;
-moz-transition: background 0.2s;
transition: background 0.2s;
}
.cd-nav-trigger span::before, .cd-nav-trigger span::after {
/* other 2 lines */
content: '';
right: 0;
/* Force Hardware Acceleration in WebKit */
-webkit-transform: translateZ(0);
-moz-transform: translateZ(0);
-ms-transform: translateZ(0);
-o-transform: translateZ(0);
transform: translateZ(0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transform-origin: 0% 50%;
-moz-transform-origin: 0% 50%;
-ms-transform-origin: 0% 50%;
-o-transform-origin: 0% 50%;
transform-origin: 0% 50%;
-webkit-transition: -webkit-transform 0.2s;
-moz-transition: -moz-transform 0.2s;
transition: transform 0.2s;
}
.cd-nav-trigger span::before {
/* menu icon top line */
top: -6px;
}
.cd-nav-trigger span::after {
/* menu icon bottom line */
top: 6px;
}
.cd-nav-trigger.nav-is-visible span {
/* hide line in the center */
background: rgba(255, 255, 255, 0);
}
.cd-nav-trigger.nav-is-visible span::before, .cd-nav-trigger.nav-is-visible span::after {
/* keep visible other 2 lines */
background: white;
}
.cd-nav-trigger.nav-is-visible span::before {
-webkit-transform: translateX(4px) translateY(-3px) rotate(45deg);
-moz-transform: translateX(4px) translateY(-3px) rotate(45deg);
-ms-transform: translateX(4px) translateY(-3px) rotate(45deg);
-o-transform: translateX(4px) translateY(-3px) rotate(45deg);
transform: translateX(4px) translateY(-3px) rotate(45deg);
}
.cd-nav-trigger.nav-is-visible span::after {
-webkit-transform: translateX(4px) translateY(2px) rotate(-45deg);
-moz-transform: translateX(4px) translateY(2px) rotate(-45deg);
-ms-transform: translateX(4px) translateY(2px) rotate(-45deg);
-o-transform: translateX(4px) translateY(2px) rotate(-45deg);
transform: translateX(4px) translateY(2px) rotate(-45deg);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment