Unable to navigate unorderlist menu via keyboard tab - html

I am trying to work out why I can not navigate our menu which uses multiple unordered lists via keyboard.
Does anyone have any tips? I have a feeling its more of a CSS issue than html.
RELATED CSS:
/* MENU */
#cssmenu{
border:none;
border:0px;
margin:0px;
padding:0px;
font: 67.5% 'Lucida Sans Unicode', 'Bitstream Vera Sans', 'Trebuchet Unicode MS', 'Lucida Grande', Verdana, Helvetica, sans-serif;
font-size:11px;
font-weight:bold;
}
#cssmenu ul{
background:#333333;
height:39px;
list-style:none;
margin:0;
padding:0;
display: table;
width: 100%;
}
#cssmenu li{
padding:0px;
display: table-cell;
width: 115px;
}
#cssmenu li a{
background:#333333 url('../images/seperator.gif') bottom right no-repeat;
color:#FFF;
display:block;
font-weight:normal;
line-height:39px;
margin:0px;
padding:0px 0px;
text-align:center;
text-decoration:none;
width: 115px;
}
#cssmenu li a:hover, #cssmenu ul li:hover a{
background: #2580a2;
color:#FFFFFF;
text-decoration:none;
float: none;
}
#cssmenu li ul{
background:#333333;
display:none;
height:auto;
padding:0px;
margin:0px;
border:0px;
position:absolute;
width:230px;
z-index:200;
/*top:1em;
/*left:0;*/
}
#cssmenu li:hover ul{
display:block;
}
#cssmenu li li {
background:url('../images/sub_sep.gif') bottom left no-repeat;
display:block;
float:none;
margin:0px;
padding:0px;
width:230px;
}
#cssmenu li:hover li a{
background:none;
}
#cssmenu li ul a{
display:block;
height:35px;
font-size:10px;
font-style:normal;
margin:0px;
padding:0px 10px 0px 15px;
text-align:left;
width: 205px;
}
#cssmenu li ul a:hover, #cssmenu li ul li:hover a{
background:#2580a2 url('../images/hover_sub.gif') center left no-repeat;
border:0px;
color:#ffffff;
text-decoration:none;
width: 205px;
}
#cssmenu p{
clear:left;
}
:focus {outline:none;}
::-moz-focus-inner {border:0;}
RELATED HTML CODE:
<div id="cssmenu"> <ul> <li>Home</li>
<li class="has-sub"> Operations <ul>
<li>Individuals
</li>
<li>Aircraft owners
</li>
<li>Aircraft operators
</li>
<li>Flight training
</li>
<li>Aerodromes
</li>
<li>Office of airspace regulation
</li>
<li>Sport aviation
</li>
<li>Class D
</li>
<li>Non-towered aerodromes
</li>
<li>Dangerous goods
</li>
<li>Ground operations
</li>
<li> Non-compliance notice
</li>
<li>Unmanned Aircraft Systems (UAS)
</li>
<li>General Aviation (GA) task force
</li>
<li>Regional Aviation Safety Forum (RASF)
</li>
<li>Drug and Alcohol Management Plans
</li>
</ul></li>
<li class="has-sub"> Airworthiness <ul>
<li>Maintenance regulations
</li>
<li>Personnel
</li>
<li>Certification and design
</li>
<li>Manufacturing
</li>
<li>Continuing airworthiness
</li>
<li>Airworthiness directives
</li>
<li>Maintenance organisations
</li>
<li>Flight test and evaluation
</li>
</ul></li>
<li class="has-sub"> Regulations & policy <ul>
<li>Current rules
</li>
<li>Changing the rules
</li>
<li>Enforcement action
</li>
<li>Policy notices
</li>
<li>Australia's state safety program
</li>
<li>Performance based navigation (PBN)
</li>
<li>Licensing regulations
</li>
</ul></li>
<li class="has-sub"> Manuals & forms <ul>
<li>Manuals
</li>
<li>Forms
</li>
<li>CASA online store
</li>
</ul></li>
<li class="has-sub"> Education <ul>
<li>AviationWorx
</li>
<li>eLearning catalogue
</li>
<li>Flight Safety Australia
</li>
<li> Pilot guides and information
</li>
<li>OnTrack
</li>
<li>Human factors
</li>
<li>Safety management systems
</li>
<li>Seminars and workshops
</li>
<li>Aviation safety advisers
</li>
<li>Advice for air travellers
</li>
<li>CASA online store
</li>
<li>Out-n-Back
</li>
</ul></li>
<li class="has-sub"> Services <ul>
<li>Licences and registrations
</li>
<li>Service standards and fees
</li>
<li>Self Service Portal
</li>
<li>Permission application centre (PAC)
</li>
<li>Aviation medicals
</li>
<li>Delegates and authorised persons
</li>
</ul></li>
<li class="has-sub"> About CASA <ul>
<li>Contact CASA
</li>
<li>CASA board
</li>
<li>CASA's Director
</li>
<li>Recent media releases
</li>
<li>Corporate publications
</li>
<li>CASA on Twitter
</li>
<li>Corporate policy
</li>
<li>Careers at CASA
</li>
<li>Research and statistics
</li>
<li>International Engagement
</li>
<li>CASA mailing lists
</li>
</ul></li>
</ul>
</div>

It is not working because you only have :hover rules which the keyboard does not trigger. When an element has tab focus it has the :focus pseudo-class, you will notice when you add this that your menu items light up when focused but still don't open the menu.
jsFiddle: With :focus rules along side :hover rules
This is due to the following rule:
#cssmenu li:hover ul,
#cssmenu li:focus ul{
display:block;
}
The li never actually gets focus because it has no tab index, the a inside of li gets focus. Since li is a parent of ul but a is a sibling of ul we need to use a different rule to get this targeting to work. We can use the next sibling selector + to target the ul based on a:focus. This gets us one step closer.
#cssmenu li:hover ul,
#cssmenu li a:focus + ul{
display:block;
}
jsFiddle with the above applied
Unfortunately this is as far as you can go with CSS (as far as I'm aware). When we try to go to the next a, :focus will be dropped on the top-level a and the menu will hide as the sub-menu will lose display:block;. Since we can't traverse up the tree when applying styles there is no way we can apply display:block to the ancestor ul when we :focus an a further down.
The only way I can see getting around this is to use JavaScript and handle the focus (and maybe blur()) event for the top-level menu items. We must then also handle the click() event to hide the menu when clicking anywhere in the document otherwise it will stay active.
jsFiddle fully working
CSS
#cssmenu li.force-show ul,
#cssmenu li:hover ul,
#cssmenu li a:focus + ul{
display:block;
}
JS
$('#cssmenu > ul > li > a').focus(function () {
$('#cssmenu > ul > li').removeClass('force-show');
$(this).parent().addClass('force-show');
});
// Clear the menu class if clicked anywhere in the document.
$(document).click(function () {
$('#cssmenu > ul > li').removeClass('force-show');
});

The problem is, that focus in CSS does not bubble up. The nearest I come is this:
/* for instance use it that way */
#cssmenu li a:hover,
#cssmenu li a:focus,
#cssmenu ul li:hover a,
#cssmenu ul li:focus a { }
The example works for the first level. But while going to the second, the first loses it's :focus, and so the submenu is hidden again. I think you need to help a bit with JavaScript.

Related

Add submenu to existing menu

Hi I have a basic menu for which I would like to add a submenu, that appears only when a certain menu link is hovered. Everything I have tried does not hide the submenu when a link is not hovered. Here is my code:
CSS
.navmenu{
float:right;
font-size: 13px;
font-weight:400;
text-transform: uppercase;
}
.navmenu li{
position: relative;
display: inline-block;
float: left;
}
.navmenu li a{
text-decoration:none;
color:#eee;
padding:15px 37px 19px 37px;
}
.navmenu li a:hover{
background:#36332e;
}
.active a{
background:#36332e;
}
HTML
<ul class="navmenu">
<li class="active">Home</li>
<li>About Us
<ul>
<li>Sub Link 1</li>
<li>SubLink 2</li>
</ul>
</li>
<li>Testimonials</li>
<li>Services</li>
<li>Contact Us</li>
</ul>
You need to initially hide the menu:
.navmenu li ul { display: none; }
and then display it when you hover over the nav item:
.navmenu li:hover ul { display: none; }
You should also be careful about defining styles that target .navmenu li or .navmenu li a because those will also target your submenu. You should instead use child selectors, giving you more control over the non-submenu links, so your selectors will look like:
.navmenu > li
.navmenu > li > a
I've encorperated some of those changes into this JSFiddle to get you started:
http://jsfiddle.net/Wexcode/B5P26/
Edit:
This is actually going to lose it's hover state when you hover over the submenu links:
.navmenu > li > a:hover {
background:#36332e;
}
Instead, you should do this:
.navmenu ul { position: absolute; }
.navmenu > li:hover { background: #e6332e; }
.navmenu > li > a { display: block; }
Since the <ul> is nested inside the <li> element, you won't lose the hover state when you hover over the submenu links. I updated the fiddle to reflect these changes.
<ul class="navmenu">
<li class="active">Home</li>
<li>About Us
<ul>
<li>
Sub Link 1
<ul>
</li> <a href=# >hi hi hi</a>
<ul>
<li>hello hello hello</li>
<li>hello hello hello</li>
<li>hello hello hello</li>
</ul>
</li>
</li><a href=# >hi hi hi</a> </li>
</li> <a href=# >hi hi hi</a> </li>
</ul>
</li>
<li>SubLink 2</li>
</ul>
</li>
<li>Testimonials</li>
<li>Services</li>
<li>Contact Us</li>
</ul>

How to fix CSS menu bug

I have a CSS3 Menu. When a menu items text is too long the design breaks. I want the text to simply move up to fit
the text. For example: At www.casa.gov.au the menu item text REGULATIONS AND POLICY starts higher than the rest
of the items. This prevents the menu width and height changing to fit the larger text.
How would I go about doing this with the menu attached in the JS FIDDLE: http://jsfiddle.net/UU4rm/
The problem is associated with the line height at #css li a { }
CSS CODE
/* MENU */
#cssmenu {
border:none;
border:0px;
margin:0px;
padding:0px;
font-size:12px;
font-weight:bold;
border-bottom: solid 1px rgb(77,77,77);
}
#cssmenu ul {
background:#333333;
height:39px;
list-style:none;
margin:0;
padding:0;
display: table;
width: 100%;
}
#cssmenu li {
padding:0px;
display: table-cell;
width: 115px;
}
#cssmenu li a {
background:#333333 url('../images/seperator.gif') bottom right no-repeat;
color:#FFF;
display:block;
font-weight:normal;
line-height:39px;
margin:0px;
padding:0px 0px;
text-align:center;
text-decoration:none;
width: 115px;
}
#cssmenu li a:hover,
#cssmenu ul li:hover a,
#cssmenu li a:focus,
#cssmenu ul li:focus a{
background: #2580a2;
color:#FFFFFF;
text-decoration:none;
float: none;
}
#cssmenu li ul {
background:#333333;
display:none;
height:auto;
padding:0px;
margin:0px;
border:0px;
position:absolute;
width:230px;
z-index:200;
/*top:1em;
/*left:0;*/
}
#cssmenu li.force-show ul,
#cssmenu li:hover ul,
#cssmenu li a:focus + ul{
display:block;
}
#cssmenu li li {
background:url('../images/sub_sep.gif') bottom left no-repeat;
display:block;
float:none;
margin:0px;
padding:0px;
width:230px;
}
#cssmenu li:hover li a,
#cssmenu li:focus li a {
background:none;
}
#cssmenu li ul a {
display:block;
height:35px;
font-size:11px;
font-style:normal;
margin:0px;
padding:0px 10px 0px 15px;
text-align:left;
width: 205px;
}
#cssmenu li ul a:hover,
#cssmenu li ul li:hover a,
#cssmenu li ul a:focus,
#cssmenu li ul li:focus a{
background:#2580a2 url('../images/hover_sub.gif') center left no-repeat;
border:0px;
color:#ffffff;
text-decoration:none;
width: 205px;
}
#cssmenu p {
clear:left;
}
:focus {
outline:none;
}
::-moz-focus-inner {
border:0;
}
HTML CODE
<div id="cssmenu"> <ul> <li>Home</li>
<li class="has-sub"> Operations <ul>
<li>Individuals
</li>
<li>Aircraft owners
</li>
<li>Aircraft operators
</li>
<li>Flight training
</li>
<li>Aerodromes
</li>
<li>Office of airspace regulation
</li>
<li>Sport aviation
</li>
<li>Class D
</li>
<li>Non-towered aerodromes
</li>
<li>Dangerous goods
</li>
<li>Ground operations
</li>
<li>Non-compliance notice
</li>
<li>Unmanned Aircraft Systems (UAS)
</li>
<li>General Aviation (GA) task force
</li>
<li>Regional Aviation Safety Forum (RASF)
</li>
<li>Drug and Alcohol Management Plans
</li>
</ul></li>
<li class="has-sub"> Airworthiness <ul>
<li>Maintenance regulations
</li>
<li>Personnel
</li>
<li>Certification and design
</li>
<li>Manufacturing
</li>
<li>Continuing airworthiness
</li>
<li>Airworthiness directives
</li>
<li>Maintenance organisations
</li>
<li>Flight test and evaluation
</li>
</ul></li>
<li class="has-sub"> Regulations & Policy <ul>
<li>Current rules
</li>
<li>Changing the rules
</li>
<li>Enforcement action
</li>
<li>Policy notices
</li>
<li>Australia's state safety program
</li>
<li>Performance based navigation (PBN)
</li>
<li>Licensing regulations
</li>
</ul></li>
<li class="has-sub"> Manuals & forms <ul>
<li>Manuals
</li>
<li>Forms
</li>
<li>CASA online store
</li>
<li>Temporary Management Instructions (TMIs)
</li>
</ul></li>
<li class="has-sub"> Education <ul>
<li>AviationWorx
</li>
<li>eLearning catalogue
</li>
<li>Flight Safety Australia
</li>
<li> Pilot guides and information
</li>
<li>OnTrack
</li>
<li>Human factors
</li>
<li>Safety management systems
</li>
<li>Seminars and workshops
</li>
<li>Aviation safety advisers
</li>
<li>Advice for air travellers
</li>
<li>CASA online store
</li>
<li>Out-n-Back
</li>
</ul></li>
<li class="has-sub"> Services <ul>
<li>Licences & registrations
</li>
<li>Self Service Portal
</li>
<li>Service standards & fees
</li>
<li>Permission application centre (PAC)
</li>
<li>Aviation medicals
</li>
<li>Delegates and authorised persons
</li>
</ul></li>
<li class="has-sub"> About CASA <ul>
<li>Contact CASA
</li>
<li>CASA board
</li>
<li>CASA's Director
</li>
<li>Recent media releases
</li>
<li>Corporate publications
</li>
<li>CASA on Twitter
</li>
<li>Corporate policy
</li>
<li>Careers at CASA
</li>
<li>Research and statistics
</li>
</ul></li>
</ul>
</div>
It looks to me (in FF), that it's the bottom border attribute that's causing a goofy black line under your menu.
#cssmenu {
border-bottom: solid 1px rgb(77,77,77);
}
Eliminating that bottom border attribute, and adding addition text to the menu items (causing a wrap/second line) acted as expected.

Why can't I see the submenu from links that are left to the one I selected?

I suppose this one might be easy for you css gurus :)
I am trying to apply some css to a page that I am currently working on where I want to have a dropline menu.
I got the code from here and just did minor modifications (width of the outer ul, class instead of id for the outer ul and z-index instead of huge negative indentation)
As I see there is some misunderstanding, here is some more detail about how this menu should work:
There are two levels, one on the top and the other underneath.
The currently selected link from the top menu will have the css-class "current" attached to the li-element that contains that link. (I use the MVC SiteMapProvider for that, but this should not matter for this question)
The submenu that is associated with that "current" top menu should be displayed by default,
but it should be overlapped by another submenu if the user hovers over the link to another top menu.
(hope that clarifies it a bit)
This is the markup I am using:
<ul class="mainMenu">
<li>
Link1
<ul>
<li>
Sub1
</li>
<li>
Sub1
</li>
<li>
Sub1
</li>
</ul>
</li>
<li class="current">
Link2
<ul>
<li>
Sub2
</li>
<li>
Sub2
</li>
<li>
Sub2
</li>
</ul>
</li>
<li>
Link3
<ul>
<li>
Sub3
</li>
<li>
Sub3
</li>
<li>
Sub3
</li>
</ul>
</li>
</ul>
and it uses these styles:
* {
margin:0;
padding:0;
}
.mainMenu {
list-style:none;
height:3.8em;
position:relative;
line-height:1.4em;
}
.mainMenu li {
width:136px;
float:left;
text-align:center;
}
.mainMenu a {
height:1.5em;
display:block;
text-decoration:none;
color:#000;
background:#999;
}
.mainMenu li.current ul li.current a, .mainMenu li.current a div, .mainMenu a:active, .mainMenu a:focus, .mainMenu a:hover {
background:#777;
}
/* --------- Sub Nav --------- */
.mainMenu li.current ul {
left:0;
}
.mainMenu ul {
position:absolute;
left: 0;
z-index: 1;
width:408px;
list-style:none;
padding:.9em 0 0;
}
.mainMenu ul li {
width:auto;
margin:0 15px 0 0;
}
.mainMenu ul a {
font-size:80%;
height:auto;
padding:0 8px;
}
.mainMenu li.current ul, .mainMenu li:hover ul {
z-index: 10;
background:#fff;
}
See also here for a fiddle that includes both already.
In general this seems to work pretty well, BUT when I hover to the right (i.e. Link1) I cannot see the corresponding links from the submenu though it works when I hover to the right (i.e. Link3). Anyone got an idea why this is the case?
ps: I also do not know why the current node is not applying the style from
.mainMenu li.current ul
(at least I do not see it in firefox 17.0.1, though, when not in the fiddle itself I do not have that problem, so probably a minor issue and not my main question here)
Just add a bit of CSS :
.mainMenu ul {
display: none;
}
.mainMenu li:hover > ul {
display: block;
}
Example
EDIT
Just change or remove z-index in .mainMenu li.current:hover ul. Fiddle
You have set class="active" to second sub menu so the first menu is under (due to z-index set) the second menu. Add active class to first menu
<ul class="mainMenu">
<li class="current">
Link1
</li>
</ul>
DEMO
You miss place current class i.e. in second menu(LINK2). Remove it and place at first link(LINK1) as below
<li class="current">
Link1.......
</li>
<li> Link2 </li>

using jquery UI - menu

I am using menu from UI
I have this ul
<ul id="menu">
<li>Loans</li>
<li>
Bancassurance
<ul>
<li>Aman el darb</li>
<li>Aman el elem</li>
<li>Aman el ghad</li>
</ul>
</li>
<li>
Services
<ul>
<li>Audi Mobile</li>
<li>Pin-Pay</li>
<li>ADSL Services</li>
<li>Bill Payment</li>
<li>Internet Accesses</li>
</ul>
</li>
<li>
Accounts
<ul>
<li>Wedding Account</li>
<li>Payroll Account</li>
<li>Saving Account</li>
<li>Current Account</li>
</ul>
</li>
</ul>
My CSS :
.ui-menu-item { }
This select all li from <ul id="menu">
How should the css selector look like so I can select the submenu `ul inside of #menu
According to your script use this .ui-menu-item #menu ul{ }
You can write like this
#menu ul li a{ css here}
DEMO
or
#menu ul li{ css here }
DEMO 2
If I am understanding your question correctly, you will need this
#menu ul {
}
If you need to target a specific UL inside of #menu, you should add an ID or Class to that particular UL and then reference it with this
#menu #example {
}
You can take it a step further and target each LI in the same fashion, like this
#menu #example li {
}
Hope this helps!
Selecting the UL inside of #menu is pretty simple:
#menu ul { /*CSS HERE*/ }

Dropdown showing differently in Firefox than in other browsers

I have a problem with Firefox I have a drop down menu at the top of my website this is the code for the CSS
#zone-bar {
background:#E5E5E5;
min-height:30px;
z-index:10;
padding:5px 10px 0;
}
#zone-bar ul li {
float:left;
height:18px;
margin-right:10px;
position:relative;
z-index:10;
padding:5px 5px 0;
}
#zone-bar ul li:hover {
background:#C0C0C0;
}
#zone-bar ul li a {
color:#383838;
display:block;
float:left;
font-size:1.1em;
font-weight:700;
height:23px;
padding-right:3px;
position:relative;
right:-5px;
text-decoration:none;
top:-5px;
}
#zone-bar ul li a:hover,#zone-bar ul li a.zoneCur {
background:url(images/right-hover.png) center right no-repeat;
z-index:10;
}
#zone-bar ul li a span {
position:relative;
top:6px;
}
#zone-bar ul li ul {
background:#FFF;
border:1px solid #ccc;
display:none;
left:0;
position:absolute;
top:29px;
width:150px;
padding:10px 0 0;
}
#zone-bar ul li ul li {
float:none;
height:100%;
margin:0;
padding:0;
}
#zone-bar ul li ul li:hover {
background:none;
}
#zone-bar ul li ul li a {
display:block;
float:none;
margin-left:-5px;
width:140px;
padding:5px 0 0 10px;
}
#zone-bar ul li ul li a:hover {
background:#C0C0C0;
}
#zone-bar ul {
display:block;
}
This is my HTML code
<div id="zone-bar">
<ul><li>
<span>My Account <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>My Account</li>
<li>My Channel</li>
<li>My Videos</li>
<li>Favorites</li>
<li>Playlists</li>
<li>Friend Requests (1)</li>
<li>Logout</li>
</ul></li>
<li>
<span>Messages <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Messages (1)</li>
<li>Compose New Message</li>
<li>Notifications (0)</li>
</ul></li>
<li>
<span>Videos <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Recent</li>
<li>Viewed</li>
<li>Featured</li>
<li>Top Rated</li>
<li>Commented</li>
</ul></li>
<li>
<span>Channels <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Recent</li>
<li >Viewed</li>
<li >Featured</li>
<li >Top Rated</li>
<li >Commented</li>
</ul></li>
<li>
<span>Groups <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Create New Group</li>
<li>All Time</li>
<li>Today</li>
<li>Yesterday</li>
<li>This Week</li>
<li>Last Week</li>
<li>This Month</li>
<li>Last Month</li>
<li>This Year</li>
<li>Last Year</li>
</ul></li>
<li>
<span>Upload <em><img src="images/arrow.png" alt="dropdown"></em></span>
<ul>
<li>Upload New Video</li>
<li>My Videos</li>
</ul></ul>
</div>
you can see a live demo at doctorwhohd.com
The problem im facing is this in normal all browsers except Firefox it looks like this when you hover over the items
In Firefox all versions i get this
Any help would be great! as this is a problem which i cannot seem to fix and im sure there is something im missing.
Your markup is really ugly for starters,
why have extra <span> tags in the top level <li> tags, why wrap your <img> tags with <em> and don't use for styling purposes.
Clean that up first.
Second, you have a lot of absolute and relative position styles that don't appear to be necessary. Have you tried styling your nav without the use of relative and absolute positioning.
The only place I see relative positioning being useful here is for the little arrow images.
Try that out.
You can give each #zone-bar ul li an explicit width (since it is the width of the li that is overrunning its content).
You may want to give each li an ID or class so that you can control their widths individually.