Instantly share code, notes, and snippets.
Last active
February 10, 2016 19:49
-
Save jeremymouton/71c9c42dceed98557396 to your computer and use it in GitHub Desktop.
Responsive navigation (depends on jQuery)
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() { | |
/* | |
* Nav collapse | |
* | |
*/ | |
$('[data-nav-collapse]').click( function(e) { | |
e.preventDefault(); | |
var target = $(this).data('nav-collapse'); | |
$(target).toggleClass('is-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
<nav class="nav" role="navigation"> | |
<div class="nav-wrapper"> | |
<div class="nav-toggle-wrapper"> | |
<a href="" class="nav-toggle" title="Show dashboard menu" data-nav-collapse=".toggle-main-nav"> | |
<span class="nav-toggle__menu">Menu</span> | |
<span class="nav-toggle__icon">≡</span> | |
</a> | |
</div> | |
<div class="nav-collapse toggle-main-nav"> | |
<ul class="nav-section"> | |
<li><a href="#">Nav item</a></li> | |
<li><a href="#">Nav item</a></li> | |
<li><a href="#">Nav item</a></li> | |
<li><a href="#">Nav item</a></li> | |
<li><a href="#">Nav item</a></li> | |
</ul> | |
</div> | |
</div> | |
</nav> |
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
@screen-xs-max: 767px; | |
@screen-sm: 768px; | |
@screen-sm-max: 991px; | |
@screen-md: 992px; | |
/** | |
* Nav | |
* | |
*/ | |
.nav { | |
border: none; | |
border-radius: 0; | |
margin-bottom: 20px; | |
} | |
.nav-wrapper { | |
@media (max-width: @screen-xs-max) { | |
padding: 0; | |
} | |
} | |
/* | |
* Nav toggle | |
* | |
*/ | |
.nav-toggle-wrapper { | |
padding: 15px; | |
line-height: 100%; | |
@media (min-width: @screen-sm) { | |
display: none; | |
} | |
} | |
.nav-toggle:active, | |
.nav-toggle:focus, | |
.nav-toggle:hover, | |
.nav-toggle { text-decoration: none; } | |
.nav-toggle { | |
display: table; | |
width: 100%; | |
} | |
.nav-toggle__icon, | |
.nav-toggle__menu { | |
display: table-cell; | |
vertical-align: top; | |
padding: 0; | |
} | |
.nav-toggle__icon { | |
padding-left: 10px; | |
text-align: right; | |
} | |
.nav-toggle__menu { text-transform: uppercase; } | |
/* | |
* Nav collapse | |
* | |
*/ | |
.nav-collapse { | |
max-height: 0; | |
transition: all .2s ease-in; | |
overflow: hidden; | |
@media (min-width: @screen-sm) { | |
max-height: none; | |
} | |
@media (min-width: @screen-md) { | |
display: table; | |
width: 100%; | |
} | |
&.is-active { | |
max-height: 500px; | |
visibility: visible; | |
} | |
} | |
/* | |
* Nav section | |
* | |
*/ | |
.nav-section { | |
list-style: none; | |
padding: 0; | |
margin: 0; | |
@media (min-width: @screen-md) { | |
display: table-cell; | |
} | |
@media (min-width: @screen-sm) and (max-width: @screen-sm-max) { | |
display: table; | |
width: 100%; | |
} | |
> li { | |
display: block; | |
position: relative; | |
@media (min-width: @screen-md) { | |
display: inline-block; | |
} | |
@media (min-width: @screen-sm) and (max-width: @screen-sm-max) { | |
display: table-cell; | |
vertical-align: middle; | |
float: none; | |
text-align: center; | |
} | |
> a { | |
display: block; | |
text-decoration: none; | |
padding: 10px 15px; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment