Reputation: 31
When the mouse hover on the menus,the menu items can show up,but I want to use "Tab" key to focus on the menu and the menu items can show up,but it doesn't work,how can I fix it?
Here's HTML
<ul class="hMenu">
<li><a href="">prod1</a>
<div>
<a href="">test1</a>
<a href="">test2</a>
<a href="">test3</a>
</div>
</li>
<li><a href="javascript:void(0);" >prod2</a>
<div>
<a href="">test4</a>
<a href="">test5</a>
</div>
</li>
</ul>
Here's css:
ul.hMenu li:hover a { color:red;}
ul.hMenu li div table{ background-color:yellow;}
ul.hMenu {
margin: 0;
padding: 0;
z-index: 1;
}
ul.hMenu li {
margin: 0;
padding: 0;
list-style: none;
float: left;
width:140px;
}
ul.hMenu li a {
display: block;
text-align: left;
text-decoration: none
}
ul.hMenu li div {
position: absolute;
display: none;
}
ul.hMenu div a {background: yellow;
}
ul.hMenu li :hover { background: yellow}
/**Mouse hover the menus can show up**/
ul.hMenu li:hover div{
display:block;
}
/**Why this line can not work when the "Tab" to focus on the menu?**/
ul.hMenu li :focus div{
display:block;
}
Upvotes: 0
Views: 4542
Reputation: 1940
If you have copied the code directly, what I see is that you have a space between your li and focus. Please remove the spaces between :hover or :focus and the previous element and try again.
Adding a space means you are referring to a descendant element which is not the case.
Upvotes: 3
Reputation: 1302
This should do it:
ul.hMenu li a:focus + div{
display:block;
}
Example: Demo
And play around a bit with
tabindex="myNumber"
in the appropriate html elements :)
Upvotes: 0
Reputation: 40639
Try this,
ul.hMenu li:focus div{
display:block;
}
And
ul.hMenu li:hover { background: yellow}
Upvotes: 0