CSS multi-level drop-down menu doesn't work - html

I'm trying to build multi-level CSS dropdown. I found a simple demo code and tried to edit but when I customized the third level of dropdown it became broken. I'm hoping to use <div> instead of <ul><li><a></a></li></ul> as I'd like to put multiple elements like <ul>, <li> and <p>. Below is the final image of the dropdown. If I hover Sub Menu 2 or Sub Menu 3, third level dropdown will appear next to each each <li> tag.
a {
text-decoration: none;
}
nav {
margin: 0 auto;
width: 600px;
height: 40px;
text-align: center;
}
nav ul {
width: 100%;
}
/* first level */
nav ul li {
position: relative;
float: left;
width: 20%;
height: 40px;
background: #fff;
}
nav ul li a {
display: block;
line-height: 40px;
color: #111;
}
nav ul li a:hover {
background: #009a9c;
color: #fff;
}
/* second level */
nav ul li ul {
position: absolute;
z-index: 100;
top: 100%;
left: 0;
width: 100%;
}
nav ul li ul li {
overflow: hidden;
width: 100%;
height: 0;
background: #43c6db;
}
nav ul li ul li a {
display: block;
color: #fff;
}
/* hover effect for second level */
nav > ul > li:hover > a {
height: 40px;
background: #009a9c;
color: #fff;
}
nav > ul > li:hover li:hover > a {
background: #009a9c;
}
nav ul li:hover > ul >li {
overflow: visible;
height: 40px;
}
/* thir level */
nav ul li ul li ul {
top: 0;
left: 100%;
}
nav ul li:last-child ul li ul {
left: 100%;
}
nav ul li ul li ul li {
width: 100%;
background: #43c6db;
}
nav ul li ul li ul li a {
display: block;
color: #fff;
}
/* hover effect for third level */
nav > ul > li > ul > li:hover > ul {
display: block;
z-index: 200;
}
nav > ul > li:hover ul >li:hover > a {
background: #009a9c;
color: #fff;
}
/* Second level arrow direction */
nav > ul > li > ul:before {
position: absolute;
content: "";
top: -20px;
right: 16px;
width: 0;
height: 0;
border: 5px solid transparent;
border-top-color: #111;
}
nav > ul > li:hover > ul:before {
border-top-color: #fff;
}
/* Third level arrow direction */
nav ul li ul li ul:before {
position: absolute;
content: "";
top: 16px;
left: -20px;
width: 0;
height: 0;
border: 5px solid transparent;
border-left-color: #fff;
}
nav ul li ul li:hover ul:before {
border-left-color: #fff;
}
nav ul li:last-child ul li ul:before {
position: absolute;
content: "";
top: 16px;
left: 200%;
margin-left: -20px;
border: 5px solid transparent;
border-right-color: #fff;
}
nav ul li:last-child ul li:hover ul:before {
border-right-color: #fff;
}
<nav>
<ul>
<li>menu 3
<ul>
<li>menu 3-1
<!-- original code I found -->
<!--<ul>
<li>menu 3-1-1</li>
</ul>-->
<!-- Want to customize like this -->
<div>
<p>Text</p>
<ul>
<li>Some menu</li>
</ul>
<ul>
<li>Some menu</li>
</ul>
</div>
</li>
</ul>
</li>
</ul>
</nav>

Your styles get overridden, for example:
/* first level */
nav ul li {
position: relative;
float: left;
width: 20%;
height: 40px;
background: #fff;
}
This style will affect all of your li elements, not just the first-level list items. You can use classes like class='first-level' or even the > operator for more specific elements selectors, like in the snippet below:
a {
text-decoration: none;
}
nav {
margin: 0 auto;
width: 600px;
height: 40px;
text-align: center;
}
nav ul {
width: 100%;
}
/* first level */
nav > ul > li {
position: relative;
float: left;
width: 20%;
height: 40px;
background: #fff;
}
nav > ul > li > a {
display: block;
line-height: 40px;
color: #111;
}
nav > ul > li > a:hover {
background: #009a9c;
color: #fff;
}
/* second level */
nav > ul > li > ul {
position: absolute;
z-index: 100;
top: 100%;
left: 0;
width: 100%;
}
nav > ul > li > ul > li {
overflow: hidden;
width: 100%;
height: 0;
background: #43c6db;
}
nav ul li ul li a {
display: block;
color: #fff;
}
/* hover effect for second level */
nav > ul > li:hover > a {
height: 40px;
background: #009a9c;
color: #fff;
}
nav > ul > li:hover li:hover > a {
background: #009a9c;
}
nav > ul > li:hover > ul >li {
overflow: visible;
height: 40px;
}
/* thir level */
nav > ul > li > ul > li > ul {
top: 0;
left: 100%;
}
nav > ul > li:last-child > ul> li> ul {
left: 100%;
}
nav >ul >li >ul >li >ul >li {
width: 100%;
background: #43c6db;
}
nav >ul >li> ul> li> ul >li> a {
display: block;
color: #fff;
}
/* hover effect for third level */
nav > ul > li > ul > li:hover > ul {
display: block;
z-index: 200;
}
nav > ul > li:hover ul >li:hover > a {
background: #009a9c;
color: #fff;
}
/* Second level arrow direction */
nav > ul > li > ul:before {
position: absolute;
content: "";
top: -20px;
right: 16px;
width: 0;
height: 0;
border: 5px solid transparent;
border-top-color: #111;
}
nav > ul > li:hover > ul:before {
border-top-color: #fff;
}
/* Third level arrow direction */
nav ul li ul li ul:before {
position: absolute;
content: "";
top: 16px;
left: -20px;
width: 0;
height: 0;
border: 5px solid transparent;
border-left-color: #fff;
}
nav ul li ul li:hover ul:before {
border-left-color: #fff;
}
nav ul li:last-child ul li ul:before {
position: absolute;
content: "";
top: 16px;
left: 200%;
margin-left: -20px;
border: 5px solid transparent;
border-right-color: #fff;
}
nav ul li:last-child ul li:hover ul:before {
border-right-color: #fff;
}
<nav>
<ul>
<li>menu 3
<ul>
<li>menu 3-1
<!-- original code I found -->
<!--<ul>
<li>menu 3-1-1</li>
</ul>-->
<!-- Want to customize like this -->
<div>
<div>Text</div>
<ul>
<li>Some menu</li>
</ul>
<ul>
<li>Some menu</li>
</ul>
</div>
</li>
</ul>
</li>
</ul>
</nav>

Related

Applying style to the active item in the HTML navigation bar

I was trying to apply some style to the active item in an HTML navigation bar, which is same as the a tag for the same.
To experiment this, I have taken the example from http://cssdeck.com/labs/css-hover-effect
Below is my modified code, where I basically created a new class "active" and replicated the same style for a:
HTML code:
<!DOCTYPE html>
<html lang = "en">
<head>
<link href='http://fonts.googleapis.com/css?family=Roboto:500,900,100,300,700,400' rel='stylesheet' type='text/css'>
<link rel = "stylesheet" type = "text/css" href = "CSS.css">
</head>
<body>
<section style="background: #e74c3c; color: #fff;">
<h2>Underline Stroke</h2>
<nav class="stroke">
<ul>
<li>Home</li>
<li>About</li>
<li>Downloads</li>
<li>More</li>
<li>Nice staff</li>
</ul>
</nav>
</section>
</body>
CSS code:
.center {
text-align: center;
}
section {
height: 100vh;
}
/* NAVIGATION */
nav {
width: 80%;
margin: 0 auto;
background: #fff;
padding: 50px 0;
box-shadow: 0px 5px 0px #dedede;
}
nav ul {
list-style: none;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul li a, nav ul li a.active {
display: block;
padding: 15px;
text-decoration: none;
color: #aaa;
font-weight: 800;
text-transform: uppercase;
margin: 0 10px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before,
nav ul li a.active:after,
nav ul li a.active:before {
transition: all .5s;
}
nav ul li a:hover {
color: #555;
}
/* stroke */
nav.stroke ul li a,
nav.fill ul li a,
nav.stroke ul li a.active,
nav.fill ul li a.active {
position: relative;
}
nav.stroke ul li a:after,
nav.fill ul li a:after,
nav.stroke ul li a.active:after,
nav.fill ul li a.active:after {
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after,
nav.stroke ul li a.active:hover:after {
width: 100%;
}
nav.fill ul li a,
nav.fill ul li a.active {
transition: all 2s;
}
nav.fill ul li a:after,
nav.fill ul li a.active:after {
text-align: left;
content: '.';
margin: 0;
opacity: 0;
}
nav.fill ul li a:hover {
color: #fff;
z-index: 1;
}
nav.fill ul li a:hover:after {
z-index: -10;
animation: fill 1s forwards;
-webkit-animation: fill 1s forwards;
-moz-animation: fill 1s forwards;
opacity: 1;
}
Unfortunately, the styles are not getting reflected in the "active" class in the navigation menu.
How to fix the error code?
Points you need to consider:
If you're going to apply the same styles for the anchor tag and the anchor tag with the class active, you don't need to mention the active classes explicitly. It applies it on all regardless of that.
If you want to have some other styles which should be applied specifically for only active class, you need to define that like I have just for demonstration changed the color of active class component to red.
.active{
...
}
Third, you got the spelling of active wrong in your html.
.center {
text-align: center;
}
section {
height: 100vh;
}
/* NAVIGATION */
nav {
width: 80%;
margin: 0 auto;
background: #fff;
padding: 50px 0;
box-shadow: 0px 5px 0px #dedede;
}
nav ul {
list-style: none;
text-align: center;
}
nav ul li {
display: inline-block;
}
nav ul li a{
display: block;
padding: 15px;
text-decoration: none;
color: #aaa;
font-weight: 800;
text-transform: uppercase;
margin: 0 10px;
}
nav ul li a,
nav ul li a:after,
nav ul li a:before{
transition: all .5s;
}
nav ul li a:hover {
color: #555;
}
/* stroke */
nav.stroke ul li a,
nav.fill ul li a{
position: relative;
}
nav.stroke ul li a:not(.active):after{
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after{
width: 100%;
}
.active{
color: #555;
}
.active:after{
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 100%;
content: '.';
background: #aaa;
height: 1px;
}
<section style="background: #e74c3c; color: #fff;">
<h2>Underline Stroke</h2>
<nav class="stroke">
<ul>
<li>Home</li>
<li>About</li>
<li>Downloads</li>
<li>More</li>
<li>Nice staff</li>
</ul>
</nav>
</section>
Update:
These two CSS styles have been updated to have the hover effect on load on the active by default.
nav.stroke ul li a:not(.active):after{
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 0%;
content: '.';
color: transparent;
background: #aaa;
height: 1px;
}
nav.stroke ul li a:hover:after{
width: 100%;
}
.active{
color: #555;
}
.active:after{
position: absolute;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 100%;
content: '.';
background: #aaa;
height: 1px;
}
It looks like you don't have any different styles to apply to just your active class. All of your styles apply to both a element and the a.active. If you want your a.active elements to be different, apply different styles.
a {
color: #fff;
}
a.active {
color: #34dd42;
}
As the previous answer said having both a and a.active on the css selector is redundant and unnecessary. Simply applying the styles to just the a element will cover both.

How to prevent menu from closing when losing mouse focus?

I built a nice drop down menu using examples I had found on the web but my manager has run into the issue that the menu can be hard to use at times because if the mouse falls off of the menu it closes. I've read a few examples on how to get around it here, but my issue is that I can't get these solutions to work with my code.
Can someone give me a few pointers? My CSS code and a html example is included below:
#cssmenu ul,
#cssmenu li,
#cssmenu span,
#cssmenu a {
padding: 0;
position: relative;
margin-left:auto;
margin-right:auto;
text-align:center;
font-family: "charles modern"
}
#cssmenu {
line-height: 1;
background: #ffffff;
margin-left:auto;
margin-right:auto;
text-align:center;
}
#cssmenu .padding{
display: block;
position: absolute;
z-index: 78;
width: 100%;
height: 100%;
top: 0px;
left: 0px;
background: none !important;
}
/* Padding amount for first-level dropdown */
#cssmenu > li > .submenu > .padding{
width: 400%;
left: -30%;
height: 160%;
}
#cssmenu .buffer{
display: block;
position: absolute;
bottom: 0px;
right: 100%;
width: 100%;
height: 100%;
background: none !important;
}
#cssmenu .shadow{
display: none !important;
}
#cssmenu:after,
#cssmenu ul:after {
content: '';
display: block;
clear: both;
}
#cssmenu a {
background: #ffffff;
color: #00A0DF;
display: block;
font-family: "charles modern", "charles modern light", Calibri, sans-serif;
font-weight: bold;
padding: 19px 20px;
text-decoration: none;
margin-left:auto;
margin-right:auto;
text-align:center;
z-index:99999;
}
#cssmenu ul {
list-style: none;
}
#cssmenu > ul > li {
display: inline-block;
float: center;
margin:0 auto;
}
#cssmenu.align-center {
text-align: center;
}
#cssmenu.align-center > ul > li {
float: none;
}
#cssmenu.align-center ul ul {
text-align: left;
}
#cssmenu.align-right > ul {
float: right;
}
#cssmenu.align-right ul ul {
text-align: right;
}
#cssmenu > ul > li > a {
color: #ffffff;
font-size: 12px;
}
#cssmenu > ul > li:hover:after {
content: '';
display: block;
width: 0;
height: 0;
position: absolute;
left: 50%;
bottom: 0;
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #0fa1e0;
margin-left: -10px;
}
#cssmenu > ul > li:first-child > a {
border-radius: 5px 0 0 0;
-moz-border-radius: 5px 0 0 0;
-webkit-border-radius: 5px 0 0 0;
}
#cssmenu.align-right > ul > li:first-child > a,
#cssmenu.align-center > ul > li:first-child > a {
border-radius: 0;
-moz-border-radius: 0;
-webkit-border-radius: 0;
}
#cssmenu.align-right > ul > li:last-child > a {
border-radius: 0 5px 0 0;
-moz-border-radius: 0 5px 0 0;
-webkit-border-radius: 0 5px 0 0;
}
#cssmenu > ul > li.active > a {
color: #047aea;
text-align: center;
padding: 14px 14px;
font-size:150%;
font-style: bold;
background: #ffffff;
}
#cssmenu > ul > li:hover > a {
background-color: #00A0DF;
color: white;
}
#cssmenu .has-sub {
z-index: 1;
}
#cssmenu .has-sub:hover > ul {
display: block;
}
#cssmenu .has-sub ul {
display: none;
position: absolute;
width: 250px;
top: 100%;
left: 0;
font-size: 100%;
}
#cssmenu.align-right .has-sub ul {
left: auto;
right: 0;
}
#cssmenu .has-sub ul li {
*margin-bottom: -1px;
}
#cssmenu .has-sub ul li a {
background: #f2f2f2;
display: block;
line-height: 120%;
padding: 6px 6px;
color: black;
font-syle: bold;
font-size: 105%;
}
#cssmenu .has-sub ul li {
background: #f2f2f2;
}
#cssmenu .has-sub ul li:hover a {
background: #00A0DF;
}
#cssmenu ul ul li:hover > a {
color: #ffffff;
}
#cssmenu .has-sub .has-sub:hover > ul {
display: block;
}
#cssmenu .has-sub .has-sub ul {
display: none;
position: absolute;
left: 100%;
top: 0;
height: 250px;
overflow: auto;
}
#cssmenu.align-right .has-sub .has-sub ul,
#cssmenu.align-right ul ul ul {
left: auto;
right: 100%;
}
#cssmenu .has-sub .has-sub ul li a {
background: #f2f2f2;
}
#cssmenu .has-sub .has-sub ul li {
background: #f2f2f2;
}
#cssmenu .has-sub .has-sub ul li a:hover {
background: #00A0DF;
}
#cssmenu ul ul li.last > a,
#cssmenu ul ul li:last-child > a,
#cssmenu ul ul ul li.last > a,
#cssmenu ul ul ul li:last-child > a,
#cssmenu .has-sub ul li:last-child > a,
#cssmenu .has-sub ul li.last > a {
border-bottom: 0;
}
<div id='cssmenu'>
<ul>
<li class='active has-sub'><center>Image 1</center></a>
<ul>
<li class='has-sub'><a href='#'><span>Add New Item</span></a></li>
<li class='has-sub'><a href='#'><span>View Item</span></a></li>
<li class='has-sub last'><a href='#'><span>Item With Sub-Items:</span></a>
<ul>
<li><a href='#'><span>User 1</span></a></li>
<li><a href='#'><span>User 2</span></a></li>
</ul>
</li>
</ul>
<li class='active has-sub'><center> Image 2</center></a>
<ul>
<li class='has-sub'><a href='#'><span>Add New Item</span></a></li>
<li class='has-sub'><a href='#'><span>View Item</span></a></li>
</ul>
</li>
</ul>
</div>
EDIT: Now using a different (simpler) method involving borders and container divs. Just change the color of the border property of .level-2-menu, .level-3-menu from red to transparent in your actual code. The only issue is the level 3 menu blocking the bottom right corner of the previous level 2 item.
new jsFiddle
It sounds like what you need is some area around each menu where you can be off the visible menu but still keep the menu open. Here is some code to demonstrate the concept. You should be able to adapt the concept into your code and style it however you like.
jsFiddle
The background-color: red is just to make the extra hover area visible for demonstration purposes.
HTML:
<div class="cssmenu">
<ul class="level-1-menu">
<li class="level-1-item">
Level 1 Item 1
<ul class="level-2-menu">
<li class="level-2-item">Level 2 Item 1</li>
<li class="level-2-item">Level 2 Item 2</li>
<li class="level-2-item">
Level 2 Item 3 with Sub-Items
<ul class="level-3-menu">
<li class="level-3-item">Level 3 Item 1</li>
<li class="level-3-item">Level 3 Item 2 longer</li>
</ul>
</li>
</ul>
</li>
<li class="level-1-item">
Level 1 Item 2
<ul class="level-2-menu">
<li class="level-2-item">Level 2 Item 1</li>
<li class="level-2-item">Level 2 Item 2 longer</li>
</ul>
</li>
</ul>
</div>
CSS:
.cssmenu {
background-color: white;
}
.cssmenu ul {
background-color: white;
list-style: none;
padding: 0;
}
.cssmenu li {
padding: 20px 0;
position: relative;
}
.cssmenu li:hover {
background-color: lightblue;
}
.cssmenu li a {
padding: 20px;
}
.level-1-menu {
text-align: center;
}
.level-1-item {
display: inline-block;
text-align: left;
}
.level-2-menu,
.level-3-menu {
display: none;
position: absolute;
white-space: nowrap;
}
.level-1-item:hover .level-2-menu,
.level-2-item:hover .level-3-menu {
display: block;
}
.level-2-menu {
left: 0;
top: 100%;
}
.level-3-menu {
left: 100%;
top: 0;
}
.level-2-item {
position: relative;
}
.level-2-item::after,
.level-3-item::after {
background-color: red;
bottom: 0;
content: '';
left: -30px;
position: absolute;
right: -30px;
top: 0;
z-index: -1;
}
.level-2-item:first-child::after,
.level-3-item:first-child::after {
top: -30px;
}
.level-2-item:last-child::after,
.level-3-item:last-child::after {
bottom: -30px;
}

Equal horizontal space between links in responsive navigation?

I am trying to make horizontal menu navigation. I have several links in navigation, and I would like to have equal horizontal space between them.
How to make links in horizontal menu with equal space between them?
HTML:
<div id="header">
<div class="secondary-navigation">
<div itemscope itemtype="http://schema.org/SiteNavigationElement">
<nav id="navigation">
<ul id="menu-main" class="menu">
<li class="menu-item">Link</li>
<li class="menu-item">Link</li>
<li class="menu-item">Link</li>
<li class="menu-item">Link</li>
<li class="menu-item">Link</li>
<li class="menu-item">Link</li>
<li class="menu-item">Link</li>
<li class="menu-item">Link</li>
</ul>
Menu
</nav>
</div>
</div>
</div>
CSS:
#header {
position: relative;
float: left;
padding: 0 0 0 0;
clear: both;
}
/*-----------------------------------------------
/* Header navigation
/*---------------------------------------------*/
.secondary-navigation {
display: block;
width: 100%;
float: left;
}
.secondary-navigation a {
vertical-align: top;
color: #F1F1F1;
font-weight: bold;
margin-top: 8px;
margin-bottom: 4px;
line-height:18px;
font-size: 15px;
border-bottom: 2px solid #333888;
}
.secondary-navigation a:hover, .secondary-navigation .sfHover {
color: #F1F1F1;
border-bottom: 2px solid #F1F1F1;
}
.secondary-navigation li li a { line-height: 1 }
.secondary-navigation a .sub {
font-size: 12px;
font-weight: normal;
color: #CFCFCF;
text-transform: none;
}
.menu-item-has-children > a:after {
content: "▼";
font-size: 10px;
color: #F1F1F1;
position: absolute;
right: 12px;
top: 22px;
}
.footer-navigation .menu-item-has-children > a:after { display: none }
.sub-menu .menu-item-has-children>a:after {
right: 0;
top: 17px;
}
.menu .current-menu-item > a { background: #fff }
.menu .current-menu-item > a:after {
content: "";
position: absolute;
width: 100%;
height: 1px;
background: #fff;
bottom: 0px;
left: 0;
z-index: 1;
}
#navigation {
margin: 0 auto;
font-size: 13px;
width: 100%;
float: left;
}
#navigation ul {
margin: 0 auto;
list-style: none; /*Added*/}
#navigation .menu { float: left; }
#navigation ul li {
float: left;
position: relative;
margin-left: 0;
}
#navigation > ul li:first-child a { }
#navigation > ul li:last-child a { border-right: 0 }
#navigation ul .header-search { float: right }
#navigation > ul > li:last-child { border-right: none }
#navigation ul li a, #navigation ul li a:link, #navigation ul li a:visited { display: block }
#navigation > ul > .current a {
background: transparent;
color: #555 !important;
}
#navigation li:hover ul, #navigation li li:hover ul, #navigation li li li:hover ul, #navigation li li li li:hover ul {
opacity: 1;
left: -228px;
top: 0;
}
#navigation ul ul {
position: absolute;
width: 226px;
z-index: 400;
font-size: 12px;
color: #333888;
border: 1px solid #F1F1F1;
background: #FFFFFF;
padding: 0;
}
#navigation ul ul li {
margin-left: 0;
padding: 0 10%;
width: 80%;
color: #333;
}
#navigation ul ul li:hover { background: #F1F1F1 }
#navigation ul ul a, #navigation ul ul a:link, #navigation ul ul a:visited {
padding: 12px 0;
position: relative;
border-left: 0;
background: transparent;
border-right: 0;
text-transform: none;
line-height: 1.4;
margin-right: 0;
min-height: 100%;
}
#navigation ul ul li:last-child a { border-bottom: none }
#navigation ul ul {
opacity: 0;
left: -999em;
}
#navigation ul li:hover ul {
left: -1px;
opacity: 1;
top: 81px;
}
#navigation ul ul li:hover ul {
top: -1px;
left: -228px;
padding-top: 0;
}
#navigation ul ul ul:after { border-color: transparent }
I tried something like this, but it does not work for me.
You can use justify-content: space-between or justify-content: space-around flexbox property
ul {
display: flex;
justify-content: space-between;
border: 1px solid black;
list-style-type: none;
padding: 10px;
margin: 0;
}
<ul>
<li>Random Link</li>
<li>Random Link</li>
<li>Random Link</li>
<li>Random Link</li>
</ul>

Submenu with z-index doesn't show

I have a submenu that shows I can not, I've given a lot of thought and I can not find the problem. I have problems with z-index property, submenu not shown me over the rest of the content. Regards thanks.
http://jsfiddle.net/9nXvT/
HTML
<html>
<body>
<div class="container">
<nav>
<ul class="site-nav">
<li>
AUCTIONS
<ul>
<li>Auction 1</li>
<li>Auction 2</li>
<li>Auction 3</li>
<li>Auction 4</li>
</ul>
</li>
<li>USERS</li>
<li>FAQ's</li>
<li>CONTACT US</li>
<li>SITE MAP</li>
</ul>
</nav>
</div>
<div class="content"></div>
</body>
</html>
CSS
.site-nav {
border-bottom: 1px solid blue;
list-style: none;
*zoom: 1;
position:relative;
z-index: 9999;
}
.site-nav:before,
.site-nav:after {
content: " ";
display: table;
}
.site-nav:after {
clear: both;
}
.site-nav ul {
list-style: none;
width: 9em;
}
.site-nav a {
color: green;
font-family: 'GothamBook';
font-size: 0.75em;
}
.site-nav li {
position: relative;
}
.site-nav > li {
float: left;
}
.site-nav > li > a {
background: white;
display: block;
padding: 12px 45px;
text-decoration: none;
}
.site-nav > li > a:hover {
background: blue;
color:red;
text-decoration: none;
}
.site-nav > li > a.last{
margin-right: 0px;
}
a.activo{
background: blue;
color: red;
text-decoration: none;
}
.site-nav li ul {
position: absolute;
display: none;
top: 36px;
width: auto;
z-index: 9999;
}
.site-nav > li.hover > ul {
display: block;
}
.site-nav li li.hover ul {
left: 100%;
top: 0;
display:block;
z-index:9999;
}
.site-nav li li a {
background: white;
font-family: 'GothamBook';
font-size: 0.8em;
display: block;
padding: 10px 0px 10px 40px;
position: relative;
width: 140px;
z-index:100;
text-align: left;
margin: 0px;
}
.site-nav li li a:hover{
background: blue;
color: purple;
}
.content{
height: 300px;
background: gray;
}
Change li.hover to li:hover and it should work.
http://jsfiddle.net/9nXvT/4/
try this one...replace .hover to :hover
.site-nav > li:hover > ul {
display: block;
}
.site-nav li li:hover ul {
left: 100%;
top: 0;
display:block;
z-index:9999;
}
http://jsfiddle.net/9nXvT/
Try this
Fiddle DEM0 http://jsfiddle.net/9nXvT/5/
CSS
.site-nav > li:hover > ul {
display: block;
}
.site-nav li li:hover ul {
left: 100%;
top: 0;
display:block;
z-index:9999;
}
Just replace these two..It will work..
.site-nav > li:hover > ul {
display: block;
}
.site-nav li li:hover ul {
left: 100%;
top: 0;
display:block;
z-index:9999;
}

CSS menu with 3 nested lists - align left problems

I have a navigation menu with 3 sub levels. I need the 3rd level list to align left but I can't get it to behave. I can get levels 2 and 3 to align relatively with the main menu but I want the 2nd level to align relatively and the 3rd level aligning completely to the left. I'd appreciate any help/advice going, here is what I have:
JSFIDDLE HERE
HTML:
<ul class="nav">
<li>LINK1</li>
<li>LINK2
<ul class="#">
<li>LINK2a
<ul class="#">
<li>LINK2b</li>
<li>LINK2c</li>
<li>LINK2d</li>
<li>LINK2e</li>
<li>LINK2f</li>
</ul>
</li>
</ul>
</li>
<li>LINK3</li>
<li>LINK4</li>
<li>LINK5</li>
</ul>
CSS:
a, img { border:none; }
* { margin:0; padding:0; }
.nav{
display:block;
list-style:none;
text-align: left;
position: relative;
height: 30px;
}
.nav li {
display: block;
position: relative;
float: left;
border: 1px solid #FFF;
}
.nav li a {
width: 125px;
height: 30px;
display: table-cell;
vertical-align: middle;
text-decoration: none;
font-size: 12px;
font-family: Arial, Verdana, Helvetica, sans-serif;
text-align: center;
color: #000;
z-index: 2000;
background-color: #999;
}
li.active {
background-color: #999 ;
color: #000;
}
.nav li a:hover {
top: 30px;
}
.nav li:hover > a {
color:#fff;
background-color:#333;
}
.nav li ul {
width: 125px;
height: 25px;
position: absolute;
left: -9999px;
border: 1px solid #FFF;
}
.nav li:hover ul {
left: -2px;
}
.nav li li:hover > a {
color:#000;
background-color:#999;
}
.nav li li{
position: relative;
border: 1px solid #FFF;
height: 25px;
}
.nav li li a {
height: 25px;
top: 25px;
text-decoration: none;
font-size: 9px;
font-family: Arial, Verdana, Helvetica, sans-serif;
text-align: center;
display: table-cell;
vertical-align: middle;
color: #000;
z-index: 2000;
background-color: #999;
}
li li.active {
background-color: #a9d9d9 ;
color: #007f7b;
}
.nav li li:hover ul {
left: -2px;
top: 25px;
}
ul.nav li > ul {
width: 700px;
height: 25px;
background-color:blue;
}
ul.nav li > ul > li > ul {
background-color:red;
height: 25px;
}
ul.nav li > ul > li { display: none; }
ul.nav li:hover li { display: block; }
Well, you are missing some simple changes CSS to make it work properly. I'll post what changes I made here to make it work:
.nav li ul became .nav li > ul
.nav li:hover ul became .nav > li:hover > ul
.nav li li:hover ul became .nav li > li:hover ul
ul.nav li > ul > li { display: none; } became ul.nav li ul ul { display: none; }
ul.nav li:hover li { display: block; } became ul.nav li:hover > ul { display: block; }
Added:
ul.nav li ul ul {
position: absolute;
top:25px;
left: -129px;
}
ul.nav li li:hover > a {
color: white;
background-color: #333
}