html - Style tab-selected element? -
i have menu bar drop-down sub menus i've created css. works fine when i'm using mouse, if use tab key select menu items, sub menu won't open , i'm unable go of sub pages without using mouse.
is there way open sub menus tab key without using js?
here's js fiddle
html
<span id="main_menu"> <span> <a href="#">page 1</a> </span> <span> <a href="#">page 2</a> <span> <span> <a href="#-history">sub page 1</a> </span> <span> <a href="#">order savings</a> </span> </span> </span> <span> <a href="#">page 3</a> </span> </span>
css
#main_menu{ background: #000; display: inline-block; padding: 10px; } #main_menu > span{ display: inline-block; vertical-align: top; } #main_menu > span:not(:first-child)::before{ content: "|"; color: #fff; font-size: 20px; font-weight: 700; margin: 0 6px; vertical-align: top; } #main_menu a{ color: #fff; font-size: 20px; font-weight: 700; text-decoration: none; } #main_menu > span > span{ display: none; } #main_menu > span:hover > span, #main_menu > span:focus > span, #main_menu > span > span:hover, #main_menu > span > span:focus{ display: block; padding-top: 1em; position: absolute; z-index: 1000; } #main_menu > span > span > span > a{ background: none repeat scroll 0 0 #000; border: 1px solid #fff; display: block; padding: 5px 7px; } #main_menu > span > span > span > a:hover, #main_menu > span > span > span > a:focus{ border-color: #00cc00; color: #00aa00; }
when tabbing focus
goes anchor
element not span
. updating css rule use a
selector, get
#main_menu > span:hover > span, #main_menu > a:focus + span > span, #main_menu > span > span:hover, #main_menu > span > a:focus + span{ display: block; padding-top: 1em; position: absolute; z-index: 1000; }
here jsfiddle.
Comments
Post a Comment