A Pen by Jean-Philippe Sirois on CodePen.
Created
February 6, 2014 15:11
-
-
Save jpsirois/8845994 to your computer and use it in GitHub Desktop.
A Pen by Jean-Philippe Sirois.
This file contains hidden or 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
<h1>Dead simple CSS only dropdown</h1> | |
<p>With JS Improved Keyboard Accessibility if needed</p> | |
<nav> | |
<ul> | |
<li><a href="javascript:">Menu A</a></li> | |
<li> | |
<span>Menu B</span> | |
<ul> | |
<li><a href="javascript:">Option B1</a></li> | |
<li><a href="javascript:">Option B2</a></li> | |
<li><a href="javascript:">Option B3</a></li> | |
</ul> | |
</li> | |
<li> | |
<span>Menu C</span> | |
<ul> | |
<li><a href="javascript:">Option C1</a></li> | |
<li><a href="javascript:">Option C2</a></li> | |
</ul> | |
</li> | |
<li> | |
<a href="javascript:">Menu D</a> | |
</li> | |
</ul> | |
</nav> |
This file contains hidden or 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
var $focused, $blurred, $navFirstLi = $('nav ul li'); | |
// Better focus support on link | |
$('nav ul ul li a').on('keyup', function(e) { | |
if (e.which === 9) { | |
$focused = $(this).parent().parent().parent() | |
if ($blurred) { | |
if ($focused != $blurred) | |
$blurred.removeClass('is-active') | |
} | |
$focused.addClass('is-active') | |
} | |
}).on('blur',function() { | |
$blurred = $(this).parent().parent().parent() | |
}) | |
$('nav > ul > li > a').on('keyup', function(e) { | |
if (e.which === 9) | |
$navFirstLi.removeClass('is-active') | |
}) |
This file contains hidden or 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" | |
body | |
font-family: 'Helvetica Neue' | |
padding: 0 20px | |
nav | |
& > ul | |
font-size: 0 | |
ul | |
padding: 0 | |
list-style-type: none | |
ul | |
position: absolute | |
left: -99999px | |
li | |
display: block | |
& > li | |
&:hover ul, | |
&.is-active ul | |
left: 0 | |
li | |
display: inline-block | |
font-size: 14px | |
font-size: 1.4rem | |
position: relative | |
a, span | |
display: block | |
color: darkblue | |
text-decoration: none | |
padding: 4px 12px | |
background: #eee | |
white-space: nowrap | |
position: relative | |
a:hover, | |
a:focus | |
outline: 0 | |
background: #ddd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment