I'm working on a three level menu. It works with two levels, however when I added a third level and hover over level 1, it displays level 2 and 3. How can I make it only display the third level when lis on level 2 are hovered over?
My html:
<div id="menuContainer">
<div id="menuwrapper">
<ul>
<li>One 1
<ul>
<li>Two 1</li>
<li>Two 2</li>
</ul>
</li>
<li>One 2
<ul>
<li>Two 3</li>
<li>Two 4</li>
</ul>
</li>
<li>One 3
<ul>
<li>
Two 5</font>
<ul>
<li><font size="2">Three 1</font></li>
<li><font size="2">Three 2</font></li>
</ul>
</li>
<li>
<font size="2">Two 6</font>
<ul >
<li><font size="2">Three 3</font></li>
<li><font size="2">Three 4</font></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
My CSS:
/*MENU CSS */
#menuwrapper {
width:100%;
z-index:2000;
}
/* for adding arrows to the menu items with sub menus YET TO IMPLEMENT*/
#menuwrapper li > a:after {
content: ' ';
}
#menuwrapper li > a:only-child:after {
content: '';
}
/* We remove the margin, padding, and list style of UL and LI components */
#menuwrapper ul, #menuwrapper ul li, #menuwrapper ul li ul li{
margin:0;
padding:0;
list-style:none;
}
/* We apply background color and border bottom white and width to 150px */
#menuwrapper ul li{
background-color:#2d6aff;
border-top:solid 1px black;
width:100%;
cursor:pointer;
}
/* We apply the background hover color when user hover the mouse over of the li component */
#menuwrapper ul li:hover{
background-color:#15357F;
position:relative;
}
/* We apply the link style */
#menuwrapper ul li a{
padding:5px 15px;
color:#ffffff;
display:inline-block;
text-decoration:none;
}
/**** SECOND LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul{
position:absolute;
display:none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul{
left:100%;
min-width:283px;
top:0px;
display:block;
}
/* we apply different background color to 2nd level menu items*/
#menuwrapper ul li ul li{
background-color:#EEEEEE;
border-left: 1px solid #999999;
width:100%;
}
/* We change the background color for the level 2 submenu when hovering the menu */
#menuwrapper ul li:hover ul li:hover{
background-color:#4cff00;
}
/* We style the color of level 2 links */
#menuwrapper ul li ul li a{
color:#000000;
display:inline-block;
width:100%;
width: auto;
}
/**** THIRD LEVEL MENU ****/
/* We make the position to absolute for flyout menu and hidden the ul until the user hover the parent li item */
#menuwrapper ul li ul li ul{
position:absolute;
display:none;
}
/* When user has hovered the li item, we show the ul list by applying display:block, note: 150px is the individual menu width. */
#menuwrapper ul li:hover ul li:hover > ul {
min-width:283px;
top:0px;
display:block;
}
/* we apply different background color to 3rd level menu items*/
#menuwrapper ul li ul li ul {
background-color:#EEEEEE;
border-left: 1px solid #999999;
width:100%;
}
/* We style the color of level 3 links */
#menuwrapper ul li ul li ul li a{
color:#000000;
display:inline-block;
width:100%;
width: auto;
}
I think you want this : See this fiddle
I added two lines of CSS in the end with playing with parent selectors :
#menuwrapper > ul > li:hover > ul { display: block; left: 0; }
#menuwrapper > ul > li:hover > ul ul { display: none; }
Related
Hi There can anyone help me i try to create a dropdown submenu but it doesn't work for me.
I dont know how to reate a nice menu.
example:
When i hover over "massages" then the menu must come down and show the submenu.
css here
.menu{
width:821px;
height:42px;
margin:0px;
background:url(images/menu.gif) no-repeat left;
}
.menu ul{
list-style:none;
padding:0 0 0 15px;
margin:0px;
}
.menu ul li{
display:inline;
}
.menu ul li ul{
display:inline;
}
.menu ul li a{
float:left;
height:42px;
border:none;
padding:0 15px 0 15px;
text-decoration:none;
color:#fff;
line-height:42px;
font-size:14px;
}
.menu ul li.aktivni-active a{
float:left;
height:42px;
border:none;
padding:0 15px 0 15px;
text-decoration:none;
line-height:42px;
font-size:14px;
Html:
<div class="menu">
<ul>
<li class="aktivni-active">Home</li>
<li>Massages</li>
<ul>
<li>Aanbiedingen</li>
</ul>
<li>Aanbiedingen</li>
<li>Prijzen</li>
<li>Agenda</li>
<li>Contact</li>
</ul>
</div>
Can anyone explane me how to create a dorpdown submenu on "Massages"
Thnx
Check with the below link.
Fiddle
/* Menu Dropdown */
ul#menu, ul#menu ul.sub-menu {
padding:0;
margin: 0;
}
ul#menu li, ul#menu ul.sub-menu li {
list-style-type: none;
display: inline-block;
}
/*Link Appearance*/
ul#menu li a, ul#menu li ul.sub-menu li a {
text-decoration: none;
color: #fff;
background: #666;
padding: 5px;
display:inline-block;
}
/*Make the parent of sub-menu relative*/
ul#menu li {
position: relative;
}
/*sub menu*/
ul#menu li ul.sub-menu {
display:none;
position: absolute;
top: 30px;
left: 0;
}
ul#menu li ul.sub-menu a {
width:150px;
}
ul#menu li:hover ul.sub-menu {
display:block;
}
/* Top Nav Background Hover */
ul#menu li a:hover {
background:#000;
}
ul#menu li ul li a:hover {
background:#999;
}
/* 3rd level nav */
ul#menu li ul.sub-menu li ul {
display:none;
position: absolute;
top: 0px;
left: 115px;
width: 100px;
}
/* show the 3rd level when the second is hover */
ul#menu li ul.sub-menu li:hover ul {
display:block;
}
/* Menu Dropdown */
You should change your markup, as far as I know submenu should be part of list item it refers to
<ul>
<li class="simple-item">item</li>
<li class="submenu">item
<ul class="submenu-goes-inside-li">
<li class="simple-item">item</li>
<li class="simple-item">item</li>
<li class="simple-item">item</li>
</ul>
</li>
</ul
In your case submenu is separated from list items.
Using the same structure you have just add class to the drop menu,
set ul inside the dropMenu to display none, then to display on however. You can use css3 or jquery to make it have a nice animation or toggle.
<div class="menu">
<ul>
<li class="aktivni-active">Home</li>
<li class="dropMenu">Massages</li>
<ul>
<li>Aanbiedingen</li>
</ul>
<li>Aanbiedingen</li>
<li>Prijzen</li>
<li>Agenda</li>
<li>Contact</li>
</ul>
</div>
CSS
.menu ul{
display:none
}
.menu:hover ul{
display:block;
}
if you want some better just use jquery http://api.jquery.com/toggle/
How do i make my second sub-menu appear when my mouse is hover my first sub-menu and on the right?
My codes.
My Fiddle
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>My Menu</title>
<link href="estilos.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
<div id="corpo">
<header>
<div id="centeredmenu">
<ul>
<li > Menu1
<ul>
<li> Menu1Sub1</li>
<li> Menu1Sub1</li>
<li> Menu1Sub1</li>
</ul>
</li>
<li> Menu2</li> <!-- e preciso criar o ficheiro-->
<li> Menu3
<ul>
<li> Menu3Sub1
<ul>
<li> Sub1Sub1</li>
<li> Sub1Sub2</li>
<li> Sub1Sub3</li>
</ul>
</li>
<li> Menu3Sub2
<ul>
<li> Sub2Sub1</li>
<li> Sub2Sub2</li>
<li> Sub2Sub3</li>
</ul>
</li>
</ul>
</li>
<li> Menu4
<ul>
<li> Menu4Sub1</li>
<li> Menu4Sub2</li>
<li> Menu4Sub3</li>
</ul>
</li>
<li> Menu5
<ul>
<li> Menu5Sub1
<ul>
<li> Sub1Sub1</li>
<li> Sub1Sub2</li>
<li> Sub1Sub3</li>
</ul>
</li>
<li> Menu5Sub2
<ul>
<li> Sub2Sub1</li>
<li> Sub2Sub2</li>
<li> Sub2Sub3</li>
</ul>
</li>
</ul>
</li>
<li> Menu6
<ul>
<li> Menu6Sub1</li>
<li> Menu6Sub2</li>
<li> Menu6Sub3</li>
</ul>
</li>
<li> Menu7
<ul>
<li> Menu7Sub1</li>
<li> Menu7Sub2</li>
<li> Menu7Sub3</li>
</ul>
</li>
<li> Menu8
<ul>
<li> Menu8Sub1
<ul>
<li> Sub1Sub1</li>
<li> Sub1Sub2</li>
<li> Sub1Sub3</li>
</ul>
</li>
<li> Menu8Sub2
<ul>
<li> Sub2Sub1</li>
<li> Sub2Sub2</li>
<li> Sub2Sub3</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</header>
</div>
</body>
body{
font-family: "Verdana", helvetica, Sans-serif;
font-size: 15px;
line-height: 20px;/*diferenca de alturas entre elementos dentro do mesmo sitio*/
background-color: #82c193;
width: 100%;
margin: auto;
}
#corpo{
min-width: 630px;
max-width: 80%;
margin: auto;
}
/* Main menu settings */
#centeredmenu {
clear:both;
float:left;
margin:0;
padding:0;
width:100%;
font-family:Verdana, Geneva, sans-serif; /* Menu font */
font-size:80%; /* Menu text size */
z-index:1000; /* This makes the dropdown menus appear above the page content below */
position:relative;
}
/* Top menu items */
#centeredmenu ul {
margin:0;
padding:0;
list-style:none;
float:right;
position:relative;
right:50%;
}
#centeredmenu ul li {
margin:0 0 0 0px;
padding:0;
float:left;
position:relative;
left:50%;
top:1px;
}
#centeredmenu ul li a {
display:block;
margin:0;
padding:10px 7px 10px 7px;
font-size:12px;
line-height:15px;
background:#eaeaea;
text-decoration:none;
color:#1f1f1f;
font-weight:bold;
border-bottom:1px solid #000;
}
#centeredmenu ul li.active a {
color:#fff;
background:#273b26;
}
#centeredmenu ul li a:hover {
background:#2b6a29; /* Top menu items background colour */
color:#fff;
border-bottom:1px solid #2b6a29;
}
#centeredmenu ul li:hover a,
#centeredmenu ul li.hover a { /* This line is required for IE 6 and below */
background:#2b6a29; /* Top menu items background colour */
color:#fff;
border-bottom:1px solid #2b6a29;
}
/* Submenu items */
#centeredmenu ul ul {
display:none; /* Sub menus are hidden by default */
position:absolute;
top:35px;
left:0;
float:left;
right:auto; /*resets the right:50% on the parent ul */
width:100px; /* width of the drop-down menus */
}
#centeredmenu ul ul li {
left:auto; /*resets the left:50% on the parent li */
margin:0; /* Reset the 1px margin from the top menu */
clear:left;
float:left;
width:100%;
}
#centeredmenu ul ul li a,
#centeredmenu ul li:hover ul li a,
#centeredmenu ul li.hover ul li a { /* This line is required for IE 6 and below */
font-size:10px;
font-weight:normal; /* resets the bold set for the top level menu items */
background:#597258;
color:#fff;
line-height:12px; /* overwrite line-height value from top menu */
border-bottom:1px solid #fff; /* sub menu item horizontal lines */
float:left;
width:100%;
}
#centeredmenu ul ul li a:hover,
#centeredmenu ul li:hover ul li a:hover,
#centeredmenu ul li.hover ul li a:hover { /* This line is required for IE 6 and below */
background:#eaeaea; /* Sub menu items background colour */
color:#273b26;
float:left;
}
/* Flip the last submenu so it stays within the page */
#centeredmenu ul ul.last {
left:auto; /* reset left:0; value */
right:0; /* Set right value instead */
}
#centeredmenu ul ul.last li {
float:right;
position:relative;
right:.8em;
}
#centeredmenu ul li:hover ul,
#centeredmenu ul li.hover ul {
display:block;
}
i would appreciate some explanations if you guys don't mind.
Thanks people.
PS: sorry my bad english.
Here is the solution for your menu.
I modified a little your example, to be transparent for me. I added new classes for your ul, li tags.
I didn't arranged the sub-submenu to right.
Here is the modified css for the menu:
body{
font-family: "Verdana", helvetica, Sans-serif;
font-size: 15px;
line-height: 20px;/*diferenca de alturas entre elementos dentro do mesmo sitio*/
background-color: #82c193;
width: 100%;
margin: auto;
}
#corpo{
min-width: 630px;
max-width: 80%;
margin: auto;
}
/* Main menu settings */
#centeredmenu {
clear:both;
float:left;
margin:0;
padding:0;
width:100%;
font-family:Verdana, Geneva, sans-serif; /* Menu font */
font-size:80%; /* Menu text size */
z-index:1000; /* This makes the dropdown menus appear above the page content below */
position:relative;
}
/* Top menu items */
#centeredmenu ul {
margin:0;
padding:0;
list-style:none;
float:right;
position:relative;
right:50%;
}
#centeredmenu ul li {
margin:0 0 0 0px;
padding:0;
float:left;
position:relative;
left:50%;
top:1px;
}
#centeredmenu ul li a {
display:block;
margin:0;
padding:10px 7px 10px 7px;
font-size:12px;
line-height:15px;
background:#eaeaea;
text-decoration:none;
color:#1f1f1f;
font-weight:bold;
border-bottom:1px solid #000;
}
#centeredmenu ul li.active a {
color:#fff;
background:#273b26;
}
#centeredmenu ul li a:hover {
background:#2b6a29; /* Top menu items background colour */
color:#fff;
border-bottom:1px solid #2b6a29;
}
#centeredmenu ul li:hover a,
#centeredmenu ul li.hover a { /* This line is required for IE 6 and below */
background:#2b6a29; /* Top menu items background colour */
color:#fff;
border-bottom:1px solid #2b6a29;
}
/* Submenu items */
.main-menu {
width: 100px;
}
.main-menu .sub-menu {
display:none; /* Sub menus are hidden by default */
position:absolute;
left:0;
float:left;
right:auto; /*resets the right:50% on the parent ul */
width:100px; /* width of the drop-down menus */
}
.main-menu:hover .sub-menu {
display:block;
}
.main-menu .sub-menu .sub-sub-menu {
display: none;
}
.sub-menu li:hover .sub-sub-menu {
display: block;
}
.sub-sub-menu {
}
#centeredmenu ul ul li {
left:auto; /*resets the left:50% on the parent li */
margin:0; /* Reset the 1px margin from the top menu */
clear:left;
float:left;
width:100%;
}
#centeredmenu ul ul li a,
#centeredmenu ul li:hover ul li a,
#centeredmenu ul li.hover ul li a { /* This line is required for IE 6 and below */
font-size:10px;
font-weight:normal; /* resets the bold set for the top level menu items */
background:#597258;
color:#fff;
line-height:12px; /* overwrite line-height value from top menu */
border-bottom:1px solid #fff; /* sub menu item horizontal lines */
float:left;
width:100%;
}
#centeredmenu ul ul li a:hover,
#centeredmenu ul li:hover ul li a:hover,
#centeredmenu ul li.hover ul li a:hover { /* This line is required for IE 6 and below */
background:#eaeaea; /* Sub menu items background colour */
color:#273b26;
float:left;
}
/* Flip the last submenu so it stays within the page */
#centeredmenu ul ul.last {
left:auto; /* reset left:0; value */
right:0; /* Set right value instead */
}
#centeredmenu ul ul.last li {
float:right;
position:relative;
right:.8em;
}
And here is the modified html:
<body>
<div id="corpo">
<header>
<div id="centeredmenu">
<ul>
<li class="main-menu"> 1
<ul class="sub-menu">
<li> 1.1</li>
<li> 1.2</li>
<li> 1.3</li>
</ul>
</li>
<li class="main-menu"> 2</li> <!-- e preciso criar o ficheiro-->
<li class="main-menu"> 3
<ul class="sub-menu">
<li> 3.1
<ul class="sub-sub-menu">
<li> 3.1.1</li>
<li> 3.1.2</li>
</ul>
</li>
<li> 3.2
<ul class="sub-sub-menu">
<li> 3.2.1</li>
<li> 3.2.2</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</header>
</div>
</body>
Here is the fix for the sub-sub-menu positioning to right. But is not working perfectly, yet.
I'm currently designing a Nav menu that includes ul, li and a elements. I'm trying to produce an effect where hovering over an a tag will only change the background color near the text for the link itself instead of the whole li area around it.
HTML:
<nav>
<div class="full_menu">
<ul>
<li>Login</li>
<li>About</li>
<li>FAQ</li>
<li>Blog</li>
<li>Our Team
<ul>
<li>Bob</li>
<li>James</li>
<li>Tom</li>
</ul>
</li><!--End team dropdown -->
</ul>
</div>
CSS:
nav {
margin:0 auto;
text-align:center;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display:block;
}
nav ul {
background: #17A74A;
padding:0px;
list-style:none;
position:relative;
display: inline;
border:0px;
}
nav ul li {
float:right;
margin-top:0px;
}
nav ul li a {
display:block;
padding:33px 40px;
color:#000;
text-decoration:none;
font-weight:bold;
font-size:18px;
}
nav ul li a:hover {
background-color:#2D6AF7;
color:#FFF;
}
nav ul ul {
background:#17A74A;
position:absolute;
top:71px;
}
nav ul ul li {
float:none;
border-bottom:1px solid #FFFFFF;
}
nav ul ul li a {
padding:15px 40px;
color:#FFF;
}
nav ul ul li a:hover {
background:#27BCDD;
}
nav ul ul ul {
position:absolute;
left:100%;
top:0;
}
I thought that by using nav ul li a:hover would fix this problem but the whole li area is still changing its background color instead of just the immediate area around the link text.
Any help would be greatly appreciated!
Do you want to achieve following result? I've removed the padding from your <a> elements and added them to the <li> elements instead.
JSFiddle
You need to change the padding to a margin if you don't want the whole thing to change color. Try this:
nav ul ul li a {
margin:15px 40px;
color:#FFF;
}
The following code creates a NAV bar with hover lists.
The hover works but I have to move my mouse quickly down the hover list to make sure it stays open on hover - ie it flashes off very quickly . Do I need to squeeze the top of the hover closer to the main NAV bar ? Any help much appreciated.
/* Navigation Style */
.dropdown { position:relative; font-family: arial, sans-serif; width:100%; height:40px; border:1px solid #666666; font-size:14px; color:#ffffff; background:#333333; z-index:2; }
/* Basic List Styling (First/Base Level) */
.dropdown ul {padding:0; margin:0; list-style: none;}
.dropdown ul li {float:left; position:relative;}
.dropdown ul li a { border-right:1px solid #666666; padding:12px 8px 12px 8px; display:block; text-decoration:none; color:#000; text-align:center; color:#fff;}
.dropdown ul li a:hover {color:#ffffff; background:#232323;}
/* Second Level Drop Down Menu */
.dropdown ul li ul {display: none;}
.dropdown ul li:hover ul { font-size:13px; display:block; position:absolute; top:41px; min-width:150px; left:0;}
.dropdown ul li:hover ul li a {display:block; background:#000; color:#ffffff; width:170px; }
.dropdown ul li:hover ul li a:hover {background:#666666; color:#ffffff;}
/* Third Level Drop Down Menu */
.dropdown ul li:hover ul li ul {display: none;}
.dropdown ul li:hover ul li:hover ul { display:block; position:absolute; left:145px; top:0; }
The actual NAV bar HTML is
<div class="dropdown">
<ul>
<li>About</li>
<li>Steam Rail Tours
<ul>
<li>All Rail Tours</li>
<li>British Pullman (VSOE)</li>
</ul>
</li>
</ul>
</div>
The problem is that your dropdown menu is 1px away from your static menu. Can be fixed by changing this one line of code:
.dropdown ul li:hover ul { font-size:13px; display:block; position:absolute; top:40px; min-width:150px; left:0;}
I changed 41px to 40px.
http://jsfiddle.net/eqH2Q/1/
Live Demo
Just add this simple rule:
.dropdown>ul>li>a:hover {
margin-bottom:20px;
}
This way when you hover the button, it gets an invisible bottom margin that will extend the area that triggers the hover event. This works with multiple dropdowns as the demo shows.
Try this line :
li:not(:hover) li {
display: none;
}
And get rid of all display: none and other hovers. It will make sublist's open when their partent list's li element is hovered, and you can add as many sublists as you want, without changing the CSS
I want to know if i can get the ul class productnav to dissappear until the mouse hovers over the product button? Also, I want the productnav ul to go off to the side like a normal menu would.
the HTML:
<div class="sidebar1" align="center">
<ul class="nav">
<li>Home</li>
<li>Products</li>
<ul class="productnav">
<li>Products Overview</li>
<li>Unibook Enterprise</li>
<li>Unibook Standard</li>
<li>Univoice 2.0</li>
<li>Univoice lite</li>
<li>Pricing</li>
<li>Demo</li>
</ul>
<li>Solutions</li>
<li>Markets</li>
<li>About UDI</li>
<li>Contact Us</li>
</ul>
Ignore any missing /div tags and such.
The CSS:
ul.nav {
margin-top: 10px;
margin-left: 2px;
list-style: none; /* this removes the list marker */
border-top: 1px solid #FFF; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
margin-bottom: 15px; /* this creates the space between the navigation on the content below */
}
ul.nav li {
border-bottom: 1px solid #FFF; /* this creates the button separation */
}
ul.nav a, ul.nav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
padding: 5px 5px 5px 15px;
display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
width: 160px; /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */
text-decoration: none;
background-color: #CFCFCF;
}
ul.nav a:hover, ul.nav a:active, ul.nav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
background-color: #1075C7;
color: #FFF;
}
/*-----------------------------*/
ul.productnav {
margin-top: 10px;
margin-left: 2px;
list-style: none; /* this removes the list marker */
border-top: 1px solid #FFF; /* this creates the top border for the links - all others are placed using a bottom border on the LI */
margin-bottom: 15px; /* this creates the space between the navigation on the content below */
}
ul.productnav li {
border-bottom: 1px solid #FFF; /* this creates the button separation */
}
ul.productnav a, ul.productnav a:visited { /* grouping these selectors makes sure that your links retain their button look even after being visited */
padding: 5px 5px 5px 15px;
display: block; /* this gives the link block properties causing it to fill the whole LI containing it. This causes the entire area to react to a mouse click. */
width: 160px; /*this width makes the entire button clickable for IE6. If you don't need to support IE6, it can be removed. Calculate the proper width by subtracting the padding on this link from the width of your sidebar container. */
text-decoration: none;
background-color: #CFCFCF;
}
ul.productnav a:hover, ul.productnav a:active, ul.productnav a:focus { /* this changes the background and text color for both mouse and keyboard navigators */
background-color: #1075C7;
color: #FFF;
}
And remember: I want a basic submenu thing going on; Hover over product, you get the .productnav ul showing up next to the normal stuff. Thanks!
Pure CSS Way
HTML
<ul class="nav">
<li>
Menu 1
<ul>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
</ul>
</li>
<li>
Menu 2
<ul>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
</ul>
</li>
<li>
Menu 3
<ul>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
<li>Sub Menu Item</li>
</ul>
</li>
</ul>
CSS
* {font-family: "Segoe UI", Tahoma;}
ul.nav {border-bottom: 1px solid #999;}
ul.nav li a {display: block; text-decoration: none; color: #333; padding: 5px; border: 1px solid #fff;}
ul.nav > li:hover {border: 1px solid #666; border-bottom: 1px solid #fff;}
ul.nav li a:hover {background: #ccc; border: 1px solid #999;}
ul.nav > li {display: inline-block; position: relative; border: 1px solid #fff;}
ul.nav > li ul {display: none; position: absolute; left: -1px; width: 150px; border: 1px solid #666; border-top-color: #fff; margin-top: 1px;}
ul.nav > li:hover ul {display: block;}
ul.nav > li ul li {display: block;} /* Vertical Menu */
ul.nav > li ul li {display: inline-block;} /* Horizontal Menu */
Fiddle: http://jsfiddle.net/vMuxA/ (Vertical Menu) http://jsfiddle.net/vMuxA/1/ (Horizontal Menu)
Steve Gibson wrote up an example on how to do css menus. He uses unordered lists.
GRC's Script-Free Pure-CSS Menuing System
/*==============================================================================
GRC multi-level script-free pure-CSS menuing system stylesheet.
This code is hereby placed into the public domain by its author
Steve Gibson. It may be freely used for any purpose whatsoever.
Computed Geometries: with a default 12px font, 1.0em == 12px and
1px == 0.08333em.
Thus, our 98px wide Freeware & Research buttons are 8.166666em wide.
==============================================================================*/
/*====== GLOBAL OVERRIDES FOR MAJOR ITEMS AND DIFFERING BROWSER DEFAULTS =====*/
body { color:#009; background:#fff; font-family: verdana, tahoma, arial, helvetica, sans-serif, MS Sans Serif; }
body, table, img, button, iframe, ul, li { margin:0; padding:0; border:0; }
table { text-align:left; }
iframe { width:0; height:0 }
ul { margin-left:20px; } /* kill default 50px left padding and set 20px */
li { margin-bottom:1em; } /* set default inter-item vertical spacing */
.tightlist li { margin-bottom:0.25em; } /* tighter list for simple bullets */
/* our default page-width div */
.pagecontainer { width:85%; text-align:left; font-size:10pt;}
/*================= STYLES FOR THE GRC MASTHEAD & CONTROLS ==================*/
.menuminwidth0 { /* for all browsers (non-IE) that obey min-width */
position:relative;
border:0;
margin:0;
padding:0;
width:100%;
height:55px;/* 36px masthead height + 18px button height + 1px lower border*/
min-width:560px;
}
/* suppress our whole menu when not an interactive mode (when printing, etc.) */
#media print, projection { .menuminwidth0 { d\isplay:none; } }
* html .menuminwidth1 { /* this allows IE5/6 to simulate min-width capability */
position:relative; /* we can simulate a minimum width by creating a large */
float:left; /* border in this first div, then placing our content */
height: 1px; /* into a second nested div (see 2nd nested div next */
border-left:560px solid #fff; /* CSS box-model borders are a fixed size */
}
* html .menuminwidth2 { /* used to simulate min-width capability for IE5/6 */
position:relative;
margin-left:-560px;
height: 1px;
}
#masthead {
position:relative; /* position our child objects relative to this div */
float:left;
vertical-align:top; /* protect from super-large user text sizing */
border:0;
margin:0;
padding:0;
width:100%; /* grey-fill the entire width */
height:36px; /* set the overall height above the menu-bar */
background:#F3F3F3; /* a very light shade of grey */
}
#mastheadlogo {
float:left;
vertical-align:top;
border:0;
padding:0;
margin:6px 0 0 7px;
}
#focus { /* GRC's focus label */
position:absolute;
border:0;
margin:0;
padding:0;
top:15px;
left:301px;
width:121px;
height:13px;
}
#search { /* search button */
position:absolute;
border:0;
margin:0;
padding:0;
top:7px;
right:6px;
width:60px;
height:19px;
}
#text { /* search text field */
position:absolute;
border:1px solid #404040;
margin:0;
padding:0 0 0 2px;
top:7px;
right:65px;
width:12em;
/* height:1.215em; we'll define this at the bottom of our style sheet */
font-size:14px !important;
background:#fefefe;
}
#yah { /* the "You are here" label graphic */
position:absolute;
top:5px;
right:99px;
width:87px;
height:9px;
}
/*========================= TOP OF THE MENU CASCADE =========================*/
.menu {
position:relative; /* establish a menu-relative positioning context */
float:left; /* play nicely with others */
margin:0;
padding:0;
border:0;
height:18px; /* the menu's overall height */
width:100%; /* we always want our menu to fill the available space */
background:#f3f3f3;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:12px; /* this (and also below) sets the menu's font size */
border-bottom:1px solid black; /* give us a black border underneath */
}
.menu img {
vertical-align: top; /* prevent images from being pushed down by text */
}
.menu ul {
padding:0;
margin:0;
border:0;
list-style-type:none; /* we don't want to view the list as a list */
line-height:1.5em; /* globally set the menu's item spacing. note */
} /* this must be 1.0 or 1.5 or 2.0 for Mozilla */
.menu li {
float:left; /* this creates the side-by-side array of top-level buttons */
position:relative; /* create local positioning contexts for each button */
margin:0;
}
.menu ul li table {
margin:-1px 0; /* IE5 needs -1px top and bottom table margins */
m\argin:0; /* re-zero the table margins for everyone but IE5 */
border-collapse:collapse; /* IE5 needs this for the sub-menus to work */
font-size:12px; /* this sets the base font size for our entire menu */
}
.drop {
display:block;
padding:0px 0.33em; /* this sets the l/r margins for our menu item */
margin:0;
text-align:right; /* this right alignment goes with the float:left below */
cursor:pointer; /* IE tries to switch back to an I-beam, don't let it */
cursor:hand; /* IE5 only knows about "hand", so set it both ways */
}
.drop span { /* this simultaneously left and right aligns the text and */
float:left; /* the >> in the drop-down menus which link to sub-menus */
}
.rightmenu {
position:relative; /* establish a local positioning context for YAH label */
float:right; /* and right-align it at the top of our page */
}
#research { /* this rightmost "Research" button must be positioned */
position:absolute; /* absolutely so that the YAH (you are here) text */
top:0px; /* label will slide underneath it under Opera v8.54 */
left:364px; /* which has a z-order sequencing bug with abs-pos elements */
}
/*======================== TOP LEVEL MENU DEFINITIONS ========================*/
.menu ul li ul {
display:none; /* initially hide the entire list hierarchy */
padding:1px; /* this is our box border width */
}
.menu ul li a,
.menu ul li a:visited { /* unselected top-level menu items */
display:block;
float:left;
text-decoration:none;
height:18px;
}
.menu ul li:hover a,
.menu ul li a:hover { /* selected top-level menu items */
border-top:1px solid #000; /* these 2 lines create the push-in illusion */
height:16px;
}
/*======================== 2ND LEVEL MENU DEFINITIONS ========================*/
.menu ul li:hover ul,
.menu ul li a:hover ul { /* 2nd level drop-down box */
display:block;
position:absolute;
margin:0;
top:18px; /* place us just up underneath the top-level images */
left:-1px; /* left-align our drop-down to the previous button border */
height:auto; /* the drop-down height will be determiend by line count */
width:13.5em;
color:black; /* this sets the unselected-text color */
background:black; /* this sets our menu's effective "border" color */
}
.menu ul li:hover ul.leftbutton,
.menu ul li a:hover ul.leftbutton {/* our first dropdown should not be skewed */
left:0px;
}
.menu ul li:hover ul.skinny,
.menu ul li a:hover ul.skinny { /* 2nd level skinny drop-down box */
width:8.08333em; /* with a 12px default font, this is 97px width (97/12) */
}
.menu ul.rightmenu li:hover ul,
.menu ul.rightmenu li a:hover ul { /* 2nd level neighborhood drop-down box */
left:auto;
right:0; /* nudge the right menu right to line up under the border */
}
* html .menu ul.rightmenu li a:hover ul { /* IE5/6 needs a tweak here */
right:-1px;
}
.menu ul li:hover ul li a,
.menu ul li a:hover ul li a { /* 2nd level unselected items */
border:0;
margin:0;
padding:0;
height:auto;
color:#000; /* this sets the unselected drop-down text color */
background:#d8d8d8; /* this sets the drop-down menu background color */
width:13.5em;
}
.menu ul li:hover ul li:hover a,
.menu ul li a:hover ul li a:hover { /* 2nd level selected item */
color:black;
background:white;
}
.menu ul li:hover ul.skinny li a,
.menu ul li a:hover ul.skinny li a,
.menu ul li:hover ul.skinny li a:hover,
.menu ul li a:hover ul.skinny li a:hover { /* 2nd level un+selected items */
width:8.08333em;
}
/*======================== 3RD LEVEL MENU DEFINITIONS ========================*/
.menu ul li:hover ul li ul,
.menu ul li a:hover ul li a ul { /* hide inactive 3rd-level menus */
visibility:hidden;
}
.menu ul li:hover ul li:hover ul,
.menu ul li a:hover ul li a:hover ul { /* 3rd level drop-down box */
visibility:visible;
position:absolute;
margin-top:-1px; /* bring the top edge of the 3rd level menu up one */
top:0;
left:8.08333em;
width:14em;
}
.menu ul li:hover ul li:hover ul li a,
.menu ul li a:hover ul li a:hover ul li a { /* 3rd level unselected items */
width:14em;
background:#d8d8d8;
}
.menu ul li:hover ul li:hover ul li a:hover,
.menu ul li a:hover ul li a:hover ul li a:hover { /* level3 selected items */
width:14em;
background:white;
}
#text { /* the Mac's standard Safari browser will not see this code */
height:1.215em;# /* ... but every other browser will and should */
} /* Safari barfs on the illegal pound sign (#) after the rule's property val */
With ul.menu being the parent of all the others, but differing from your html approach in this : the submenus (ul tags) are inside a parent's menu item (li tag), which is more consistent with html requirements (a w3 recommendation, a question, or just test it in the validator).
So your example would become the following :
<div class="sidebar1" align="center">
<ul class="nav">
<li>Home</li>
<li>Products
<ul class="productnav">
<li>Products Overview</li>
<li>Unibook Enterprise</li>
<li>Unibook Standard</li>
<li>Univoice 2.0</li>
<li>Univoice lite</li>
<li>Pricing</li>
<li>Demo</li>
</ul>
</li>
<li>Solutions</li>
<li>Markets</li>
<li>About UDI</li>
<li>Contact Us</li>
</ul>
And the css I would use (even though you could strip the sizes, as long as they're all the same, I think) :
.nav li
{
position:relative;
float:left;
width:180px;
height:30px;
padding:0;
margin:0;
list-style: none;
}
.nav ul
{
display:none;
position:absolute;
padding:0;
margin:5px 0 0 0;
}
.nav ul li ul
{
left:100%;
top:0;
margin:0px;
}
/* hiding or showing on second generations */
.nav li:hover ul ul, .nav li:hover ul ul ul
{
display: none;
}
.nav li:hover ul, .nav ul li:hover ul, .nav ul ul li:hover ul
{
display: block;
}
This works on up to three recursive levels of uls in your ul.nav, but you could expand it as much as you'd want by modifying the selectors of the two last css blocks.
But I still think that replacing the :hover with a .over class that appears on hover with hover events in javascript gives a better feeling, because you can set a timeout to keep the menu shown for a short moment after having hovered it. Allows for more natural moves with your pointer when navigating to a sub-menu, with the css approach you have to stay inside the li tags.