Skip to content

Instantly share code, notes, and snippets.

@cshold
Last active Aug 29, 2015
Embed
What would you like to do?
Timber Tutorial | Responsive Navigation
// ==============================================================================
// #Site Nav and Dropdowns
// ==============================================================================
.nav-bar {
background-color: $colorNav;
a {
color: $colorNavText;
&:hover,
&:focus {
color: darken($colorNavText, 15%);
}
}
ul {
margin: 0;
}
li {
margin: 0;
}
}
.site-nav {
font-size: 18px;
font-family: $specialFontStackBold;
text-transform: uppercase;
cursor: default;
li {
margin: 0;
display: block;
}
a {
display: block;
text-decoration: none;
}
.customer-navlink {
color: $colorNavText;
background-color: lighten($colorNav, 15%);
border-bottom: 0;
border-top: 1px solid lighten($colorNav, 5%);
margin-top: -1px;
}
}
// Small screen nav styles
@include at-query ($max, $medium) {
.nav-bar {
position: fixed;
top: 110%;
bottom: 0;
left: 0;
right: 0;
padding-bottom: $mobileNavBarHeight;
z-index: 2000;
@include transition(all 600ms cubic-bezier(0.47, 0.5, 0, 0.95));
.show-nav & {
top: $mobileNavBarHeight;
bottom: 0;
max-height: 100%;
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
@include transition(all 450ms cubic-bezier(0.47, 0, 0, 0.95));
}
.wrapper {
padding: $gutter/2 0 0;
}
.search-bar {
margin: 0 $gutter/2 $gutter/2;
width: auto;
}
}
.site-nav {
border-top: 1px solid lighten($colorNav, 20%);
}
// Menu items
.site-nav li {
padding: $gutter/2;
border-bottom: 1px solid lighten($colorNav, 20%);
-webkit-tap-highlight-color: rgba(255,255,255,0.2);
&:hover {
background-color: lighten($colorNav, 10%);
}
}
}
// Medium screen size only
@include at-query (null, $postSmall, $medium) {
.site-nav {
@include clearfix;
}
.site-nav li {
width: 50%;
float: left;
&:nth-child(2n) {
border-left: 1px solid lighten($colorNav, 20%);
}
}
}
// Large screen bar navigation
@include at-query ($min, $large) {
.nav-bar {
.search-bar {
display: none;
}
}
.site-nav {
text-align: left;
& > li {
position: relative;
display: inline-block;
&:first-child {
a {
padding-left: 0;
}
}
}
a {
padding: $gutter/2;
white-space: nowrap;
}
}
}
// Dropdowns
.site-nav--dropdown {
position: absolute;
top: 100%;
left: 0;
z-index: 5;
border: 1px solid $borderColor;
background-color: $colorBody;
max-height: 0;
opacity: 0;
overflow: hidden;
@include transition('max-height 0.4s ease-out, opacity 0.15s ease-out 0.1s');
@include at-query ($min, $large) {
.site-nav--has-dropdown:hover & {
max-height: 600px;
opacity: 1;
box-shadow: 0 5px 40px rgba(0,0,0,0.05);
@include transition('max-height 0.05s ease-in, opacity 0s ease-out');
}
}
a {
color: $colorPrimary;
text-transform: none;
padding: $gutter/4 $gutter*1.5 $gutter/4 $gutter/2;
&:hover,
&:active {
opacity: 0.8;
}
}
li:first-child a {
padding-top: $gutter/2;
}
li:last-child a {
padding-bottom: $gutter/2;
}
}
.site-nav--has-dropdown > a {
position: relative;
padding-right: $gutter;
&:after {
content: '';
display: block;
position: absolute;
top: 50%;
right: 0;
margin-top: -4px;
height: 8px;
width: 8px;
background: {
image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iMjIuM3B4IiBoZWlnaHQ9IjQwcHgiIHZpZXdCb3g9IjAgMCAyMi4zIDQwIiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCAyMi4zIDQwIiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGZpbGw9IiNEM0QzRDMiIGQ9Ik0wLjUsMy4xYzIuMSwyLjEsMTYuMSwxNi42LDE2LjEsMTYuNlMyLjYsMzQuOCwwLjUsMzYuOVMzLjYsNDAsMy42LDQwbDE4LjctMjAuM0wzLjYsMEMzLjYsMC0xLjYsMSwwLjUsMy4xDQoJeiIvPg0KPC9zdmc+DQo=");
// image: url({{ 'arrow-right.svg' | asset_url }});
repeat: no-repeat;
position: 0 0;
size: 8px 8px;
}
@include at-query ($min, $large) {
right: 10px;
margin-top: -7px;
height: 10px;
width: 10px;
background: {
image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBHZW5lcmF0b3I6IEFkb2JlIElsbHVzdHJhdG9yIDE3LjEuMCwgU1ZHIEV4cG9ydCBQbHVnLUluIC4gU1ZHIFZlcnNpb246IDYuMDAgQnVpbGQgMCkgIC0tPgo8IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPgo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4IgoJIHdpZHRoPSI3LjdweCIgaGVpZ2h0PSI0LjNweCIgdmlld0JveD0iMCAwIDcuNyA0LjMiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDcuNyA0LjMiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8cGF0aCBmaWxsPSIjRkZGRkZGIiBkPSJNNy4xLDAuMUM2LjcsMC41LDMuOSwzLjIsMy45LDMuMlMxLDAuNSwwLjYsMC4xUzAsMC43LDAsMC43bDMuOSwzLjZsMy44LTMuNkM3LjcsMC43LDcuNS0wLjMsNy4xLDAuMXoiLz4KPC9zdmc+Cg==");
// image: url({{ 'arrow-white.svg' | asset_url }});
size: 10px 10px;
}
}
}
}
// ==============================================================================
// #Mobile Nav Bar
// ==============================================================================
#mobileNavBar {
@include clearfix;
display: none;
width: 100%;
background-color: $colorNav;
@include at-query ($max, $medium) {
display: block;
.show-nav & {
position: fixed;
left: 0;
top: 0;
}
}
}
@include at-query ($max, $small) {
body.show-nav {
overflow: hidden;
padding-bottom: $mobileNavBarHeight;
}
}
.mobileNavBar-link {
border: 0 none;
background: none;
padding: $gutter/3;
margin: 0;
display: block;
float: right;
color: $colorNavText;
&:hover,
&:focus {
color: $colorNavText;
}
&:first-child {
float: left;
}
&.menu-toggle {
padding-left: 40px;
background: {
repeat: no-repeat;
position: 15px center;
image: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAxNy4xLjAsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjwhRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cudzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+DQo8c3ZnIHZlcnNpb249IjEuMSIgaWQ9IkxheWVyXzEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB3aWR0aD0iMjAuOHB4IiBoZWlnaHQ9IjE3cHgiIHZpZXdCb3g9IjAgMiAyMC44IDE3IiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMiAyMC44IDE3IiB4bWw6c3BhY2U9InByZXNlcnZlIj4NCjxwYXRoIGZpbGw9IiNGRkZGRkYiIGQ9Ik0xOS43LDJIMS4xQzAuNiwyLDAsMi41LDAsM2MwLDAuNywwLjYsMS4xLDEuMSwxLjFoMTguNmMwLjYsMCwxLjEtMC41LDEuMS0xQzIwLjgsMi41LDIwLjMsMiwxOS43LDJ6Ii8+DQo8cGF0aCBmaWxsPSIjRkZGRkZGIiBkPSJNMTkuNyw5LjRIMS4xYy0wLjYsMC0xLjEsMC41LTEuMSwxYzAsMC43LDAuNiwxLjEsMS4xLDEuMWgxOC42YzAuNiwwLDEuMS0wLjUsMS4xLTENCglDMjAuOCw5LjksMjAuMyw5LjQsMTkuNyw5LjR6Ii8+DQo8cGF0aCBmaWxsPSIjRkZGRkZGIiBkPSJNMTkuNywxNi44SDEuMWMtMC42LDAtMS4xLDAuNS0xLjEsMUMwLDE4LjUsMC42LDE5LDEuMSwxOWgxOC42YzAuNiwwLDEuMS0wLjUsMS4xLTENCglDMjAuOCwxNy4zLDIwLjMsMTYuOCwxOS43LDE2Ljh6Ii8+DQo8L3N2Zz4NCg==");
// image: url({{ 'hamburger.svg' | asset_url }});
size: 15px auto;
}
.lt-ie9 {
background-image: none;
padding-left: 0;
}
}
&.cart-toggle {
background-size: 20px auto;
padding-left: 45px;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment