Last active
December 15, 2015 09:19
-
-
Save jorgepinon/5237145 to your computer and use it in GitHub Desktop.
A CodePen by Jorge Luis Piñon. 3 .nav types, with togglers - .nav
.nav--pills (extends .nav)
.nav--stacked (extends .nav) For small screens a toggle link appears that expands an each navigation. TODO: method to alternate nav types repsonsively. For example, nav--stacked becomes nav--pills at a given breakpoint
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
$(document).ready(function() { | |
$('body').addClass('js'); | |
var $navlinks = $('.nav-link'); | |
$navlinks.each(function(){ | |
$(this).on('click', function(e) { | |
e.preventDefault(); | |
$(this).toggleClass('active').next('.nav--toggled').toggleClass('active'); | |
}); | |
}); | |
}); |
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
@import "compass"; | |
a { | |
color: #69c; | |
} | |
section { | |
border-top: solid 3px #ddd; | |
margin: 3em 0 5em; | |
} | |
.nav { | |
margin: 0; | |
padding: 0; | |
> li { | |
display: inline-block; | |
> a { | |
display: inline-block; | |
padding: 0.5em .75em; | |
} | |
} | |
} | |
/* extends .nav, separate links */ | |
.nav--pills { | |
clear: left; | |
overflow: hidden; | |
margin-bottom: 1em; | |
> li { | |
margin: 0; | |
display: inline-block; | |
> a { | |
border: 1px solid #ccc; | |
margin: 0 .5em .5em 0; | |
text-decoration: none; | |
} | |
} | |
} | |
/* extends .nav, aka window shade */ | |
.nav--stacked { | |
margin-bottom: 1em; | |
border-top: 1px solid #ccc; | |
> li{ | |
display:list-item; | |
> a { | |
display:block; | |
white-space: nowrap; | |
border-bottom: 1px solid #ccc; | |
text-decoration: none; | |
padding: .75em; | |
&:hover, &:active { | |
color: #fff; | |
background-color: #69c; | |
text-decoration: none; | |
} | |
} | |
} | |
} | |
/* toggler element goes with nav--toggled on ul */ | |
.nav-link { | |
float: left; | |
padding: 1em; | |
} | |
.nav--toggled { | |
clear: both; | |
-webkit-transition: all 0.15s ease-out; | |
-moz-transition: all 0.15s ease-out; | |
-ms-transition: all 0.15s ease-out; | |
-o-transition: all 0.15s ease-out; | |
transition: all 0.15s ease-out; | |
} | |
.js .nav--toggled { | |
overflow: hidden; | |
max-height: 0; | |
} | |
.nav--toggled.active { | |
max-height: none; | |
} | |
@media screen and (min-width: 48.25em) { | |
.nav-link { | |
display: none; | |
} | |
.js .nav--toggled { | |
max-height: none; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment