Last active
December 27, 2015 15:39
-
-
Save beaucharman/7348970 to your computer and use it in GitHub Desktop.
Accessible, lightweight drop down menus. http://jsfiddle.net/beaucharman/X2ArC/
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
/** | |
* usage | |
*/ | |
;(function ($) { | |
$(".drop-down-menu_accessible").accessibleDropDownMenu(); | |
})(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
/** | |
* Collapsible horizontal list | |
*/ | |
/*ul*/.list--horizontal { | |
list-style-type: none; | |
padding-left: 0; | |
} | |
li, | |
.list-item { | |
margin-right: 1.5em; | |
margin-bottom: 0; | |
float: left; | |
} | |
li:last-child, | |
.list-item:last-child { | |
margin-right: 0; | |
} | |
/* Clearfix */ | |
.clearfix { | |
*zoom: 1; | |
} | |
.clearfix :before, | |
.clearfix :after { | |
content: " "; | |
display: table; | |
} | |
.clearfix :after { | |
clear: both; | |
} | |
/** | |
* Dropdown navigation | |
*/ | |
/*nav*/.nav { } | |
.nav .ul { | |
width: 100%; | |
position: relative; | |
z-index: 5; | |
} | |
/** | |
* Parent menu item | |
*/ | |
.nav .li { | |
position: relative; | |
} | |
.nav a, | |
.nav a:link, | |
.nav a:visited { | |
} | |
.nav a:hover, | |
.nav a:focus{ | |
} | |
.nav a:active { | |
} | |
/** | |
* Sub navigation | |
*/ | |
.nav .sub-ul { | |
position: absolute; | |
left: -9999px; | |
padding-top: 0.25em; /* Slight Offset */ | |
box-shadow: 0 6px 8px -8px #000; /* Optional depth */ | |
list-style: none; | |
padding-left: 0; | |
} | |
/** | |
* Child menu item | |
*/ | |
.nav .sub-li { | |
float: none; | |
} | |
/* Child item anchor */ | |
.nav .sub-a { | |
white-space: nowrap; /* Stop text wrapping and creating multi-line dropdown items */ | |
display: block; | |
min-width: 160px; | |
} | |
/* Bring the sub navigation in */ | |
.nav .sub-a:hover .sub-ul, | |
.nav .sub-a.focus .sub-ul { | |
left: 0; | |
} | |
/* Optional fix for right browser edge navigation elements */ | |
.nav .sub-a:last-child:hover .sub-ul, | |
.nav .sub-a:last-child.focus .sub-ul { | |
//left: -$160px; | |
} | |
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
/** | |
* Collapsible horizontal list | |
*/ | |
/*ul*/.list--horizontal { | |
list-style-type: none; | |
padding-left: 0; | |
li, | |
.list-item { | |
margin-right: 1.5em; | |
margin-bottom: 0; | |
float: left; | |
&:last-child { | |
margin-right: 0; | |
} | |
} | |
} | |
/* Clearfix */ | |
%clearfix { | |
*zoom: 1; | |
&:before, | |
&:after { | |
content: " "; | |
display: table; | |
} | |
&:after { | |
clear: both; | |
} | |
} | |
/** | |
* Set a nav item max width | |
* Used with the offset helper as well | |
*/ | |
$item-max-width: 160px; | |
/** | |
* Dropdown navigation | |
*/ | |
/*nav*/.nav { | |
/*ul*/.ul { | |
@extend %clearfix; | |
@extend .list--horizontal; /* List style and floa stuff */ | |
width: 100%; | |
position: relative; | |
z-index: 5; | |
/** | |
* Parent menu item | |
*/ | |
.li { | |
position: relative; | |
.a { | |
&, | |
&:link, | |
&:visited { | |
} | |
&:hover, | |
&:focus{ | |
} | |
&:active { | |
} | |
} | |
/** | |
* Sub navigation | |
*/ | |
.sub-ul { | |
position: absolute; | |
left: -9999px; | |
padding-top: 0.25em; /* Slight Offset */ | |
box-shadow: 0 6px 8px -8px #000; /* Optional depth */ | |
list-style: none; | |
padding-left: 0; | |
/** | |
* Child menu item | |
*/ | |
.sub-li { | |
float: none; | |
/* Child item anchor */ | |
.sub-a { | |
white-space: nowrap; /* Stop text wrapping and creating multi-line dropdown items */ | |
display: block; | |
min-width: $item-max-width; | |
} | |
} | |
} | |
/* Bring the sub navigation in */ | |
&:hover .sub-ul, | |
&.focus .sub-ul { | |
left: 0; | |
} | |
/* Optional fix for right browser edge navigation elements */ | |
&:last-child:hover .sub-ul, | |
&:last-child.focus .sub-ul { | |
//left: -$item-max-width; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment