I've been following a web tutorial to create a cascading menu for a system I am developing, it is ok but I have the following problem on my 3rd level menu layer:
When my cursor is above a list item of 2nd layer:
When I move the cursor to the last layer, the link of the active list item changes it color, becoming invisible:
The structure is somewhat like that:
...
<nav>
<ul>
<li><a> Cadastro <a/>
<ul>
<li>
<a>Produtos<a/>
<ul>
<li>
<a>Adicionais<a/>
</li>
<li>
<a>Produtos<a/>
</li>
<li>
<a>"Tamanhos"<a/>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
and this is the css I'm using actually:
nav ul ul {
display: none;
background: #FFD200;
padding: 0;
width: auto;
position: absolute;
top: 100%;
z-index: 1;
}
nav ul ul li {
float: none;
position: relative;
z-index: 2;
}
nav ul ul li a {
padding: 10px 45px;
font-size: 17x;
color: #3F1312;
}
nav ul ul li a:hover {
background: #3F1312;
}
nav ul ul ul {
position: absolute;
left: 100%;
top:0;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #FFD200;
list-style: none;
width: 100%;
position: relative;
display: inline-table;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #3F1312;
}
nav ul li:hover a {
color: #FFD200;
font-size: 17px;
}
nav ul li:hover ul li a {
color: #3F1312;
}
nav ul li:hover ul li a:hover {
color: #FFD200;
}
nav ul li a {
display: block;
padding: 10px 45px;
color: #3F1312;
font-size: 17px;
text-decoration: none;
font-weight: bold;
}
nav ul:after {
content: "";
clear: both;
display: block;
}
I need to know what css rule I have to apply to make it work. Any help is welcome.
You need to set :hover property to the li element and not to "a" element.
see the difference below
nav ul ul li a:hover {
background: #3F1312;
}
/* Replace below code instead of Above one*/
nav ul ul li:hover a {
background: #3F1312;
}
nav ul li:hover ul li a:hover {
color: #FFD200;
}
/* Replace below code instead of Above one*/
nav ul li:hover ul li:hover a {
color: #FFD200;
}
Edit
Checkout following rules, You will need to add these rules into your css to avoid third level menu problem
nav ul li:hover ul li:hover ul li a{
color: #3F1312;
background: #FFD200;
}
nav ul li:hover ul li:hover ul li:hover a{
color: #FFD200;
background: #3F1312;
}
Related
My sub menu is disappearing on hover. When I hover over the menu item it appears but when i try to go to the sub menu item.. it goes away. Any idea why?
I have tried doing this:
.nav ul li:hover ul {
display: block !important;
}
But i still have the same issue. Any help will be appreciated!
HTML:
<div class="nav">
<ul>
<li>
Testing
<ul>
<li>Testing 1</li>
</ul>
</li>
</ul>
</div>
CSS:
.nav ul {
letter-spacing: 2px;
margin-top: 10px;
}
.nav ul li {
display: inline-block;
border-right: 1px solid #7d7a7a;
}
.nav ul ul li {
border-right: none;
}
.nav ul li:last-child {
border-right: none;
}
.nav ul li a {
display: inline-block;
color: #000;
text-decoration: none;
padding: 0 10px;
height: 80%;
}
.nav ul li a i {
color: #000;
}
.nav ul ul li:hover ul {
display: block;
}
.nav ul li:hover ul {
display: block !important;
}
.nav ul li ul {
position: absolute;
display: none;
background-color: #333;
height: auto;
top: 34px;
padding: 13px 10px;
}
.nav ul li ul li:hover {
background-color: #47a3da;
}
JSFiddle demo
It's happening because there is a gap between the dropdown and the button.
You need to get rid of any margin and top for the dropdown to be right under the button.
Demo
.nav > ul {
letter-spacing: 2px;
margin-top: 10px;
}
.nav ul li ul {
position: absolute;
display: none;
background-color: #333;
height: auto;
padding: 13px 10px;
}
Since you parent li and its dropdown menu-item has extra space between them, dropdown ul losses the event of .nav ul li ul li:hover. To make it work,
simply adjust the vertical distance b/w parent and its dropdown child menu-item
.nav ul li ul {
position: absolute;
display: none;
background-color: #333;
height: auto;
top: 18px; /* Works fine on 18px*/
padding: 13px 10px;
}
JSFiddle
I'm stuck with a dropdown menu i made.
When I hover a menu item, a dropdown appears, but i can't seem to click the dropdown items because there is a blank space between the dropdown and the menu.
this is my code:
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
float : right;
padding: 0px 10px;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #fff;
}
nav ul li:hover a {
color: #000;
}
nav ul li a {
display: block; padding: 0px 10px;
color: #757575; text-decoration: none;
}
nav ul ul {
background: #fff; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 0px 20px;
color: #fff;
}
nav ul ul li a:hover {
background: #fff;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
does anyone has an idea?
you can see the code in : http://dropdown.kiran.be
ty
K
just add
left:0
to your nav ul ul (drop down menu)
and remove the margin-bottom from nav ul li (it inherits some margin from your base.css you can see whats going on if you use firebug)
Basically, you make the UL appear when you hover a li:
HTML
<ul>
<li>one</li>
<li>two
<ul class="sub">
<li>sub one</li>
<li>sub two</li>
</ul>
</li>
</ul>
CSS
ul li ul {
display:none;
position:absolute;}
ul li:hover ul.sub {
display:block;
}
Hope that helps!
You should remove the ul margin that you have now. So this is a possible solution:
ul li ul {
margin-left: 0;
}
You should even remove the margin on top of the drop-down menu. I can't click on it because it slips away!
I have been searching the internet. This question Hovering <a> in CSS without href on Stack Overflow, doesn't address my issue in a way I can understand.
I am trying to make a "primary" menu, with no links.
From each item in the menu, I'd like to create a drop down menu when hovering or clicking upon the item.
I would like to do this with CSS only.
I am having confusion. I have tried various permutations with z-index, positioning and visibility. However, I am finding it hard to achieve the result I need. I have also tried having links in the outside list items.
This is my code:
HTML:
<ul>
<li>Name 1
<ul>
<li>anteater</li>
<li>bee</li>
<li>cat</li>
<li>dog</li>
</ul>
</li>
<li>Name 2
<ul>
<li>egg</li>
<li>fern</li>
<li>goose</li>
<li>house</li>
</ul>
</li>
</ul>
CSS:
ul {
list-style-type: none;
margin: 0;
padding: 0;
}
li {
float: left;
padding: 30px 15px 20px 15px;
border-right: dotted #FFFFFF 1px;
color: #FFFFFF;
font-size: 11px;
position: relative;
z-index: 3;
}
li.end {
float: right;
}
a {
display: block;
text-decoration: none;
}
a:link {
color: #FFFFFF;
}
a:visited {
color: #FFFFFF;
}
a:hover {
color: #0099FF;
}
a:active {
color: #FFFFFF;
overflow: visible;
}
ul li:active ul, ul ul {
visibility:visible;
}
ul li:active ul, ul ul li {
visibility:visible;
}
ul li:hover ul, ul ul {
visibility: visible;
}
ul li:hover ul, ul ul li {
visibility:visible;
}
ul ul {
list-style-type: none;
margin: 0;
position: absolute;
visibility: hidden;
z-index:-1;
}
ul ul li {
float: left;
padding: 5px 10px;
border-right: dotted #0000FF 1px;
background-color: #000000;
color: #FFFFFF;
font-size: 11px;
position: relative;
visibility:hidden;
}
ul ul li a {
display: block;
text-decoration: none;
}
ul ul li a:link {
color: #0000FF;
}
ul ul li a:visited {
color: #0000FF;
}
ul ul li a:hover {
color: #FFFFFF;
visibility:visible;
}
ul ul li a:active {
color: #FFFFFF;
overflow: visible;
visibility:visible;
}
See this example http://jsfiddle.net/La2L8/
I think you have excessive CSS code
Recently a few months ago I had to add sublevel functionality into a drop down menu on one of our sites. The tactic I took before worked well for the one column in the navigation, but I was asked to add a sublevel to the column before it which didn't work because I was using relative positioning (see the example below):
<style type="text/css">
#div#mycontent { overflow: visible; }
#nav ul { font-family: Arial, Verdana; font-size: 10px; margin: 0; padding: 0; list-style: none; font-weight: bold; }
#nav ul li { display: block; float: left; margin: 0;}
#nav li ul { display: none; }
#nav ul li a { display: block; text-decoration: none; color: #3c1c4e; border-top: 1px solid #ffffff; padding: 5px 15px 5px 15px; background: #f0e8d8; margin-left: 1px; white-space: nowrap; }
#nav ul li a:hover { background: #f0e8d8; }
#nav li:hover ul { display: block; position: absolute; }
#nav li:hover li { float: none; font-size: 11px; }
#nav li:hover a { background: #f0e8d8; }
#nav li:hover li a:hover { background: #fff7e7; }
/* This is for sublevels in the drop down */
#nav li:hover ul li ul {display: none}
#nav li ul li:hover ul { display: block; }
#nav li ul li ul li { position: relative; left: 188px; bottom:25px ;padding-left:1px }
So I modified the sublevels in the drop down menu to use relative positioning used an overlap approach (due to the way to previous coder originally designed the drop down). The new code looks like the one below:
#nav li ul li ul li { position: absolute; left: 125px; bottom: 0px; border-style: solid; border-width: 1px; border-color:purple; z-index: 1; }
However as the title indicates the LI under the unordered list are now stacking on top of one another. Instead of displaying vertically one after the other. I believe it requires me to clear the float, but it looks like it was done up above. So I'm unsure if I need to redefine the float then clear it in order to make sure the links in the sub list will display vertically.
Edit:
A good thought to add the HTML to show how I'm trying to execute this:
<html>
<head>
<style type="text/css">
#div#mycontent { overflow: visible; }
#nav ul { font-family: Arial, Verdana; font-size: 10px; margin: 0; padding: 0; list-style: none; font-weight: bold; }
#nav ul li { display: block; float: left; margin: 0;}
#nav li ul { display: none; }
#nav ul li a { display: block; text-decoration: none; color: #3c1c4e; border-top: 1px solid #ffffff; padding: 5px 15px 5px 15px; background: #f0e8d8; margin-left: 1px; white-space: nowrap; }
#nav ul li a:hover { background: #f0e8d8; }
#nav li:hover ul { display: block; position: absolute; z-index: 0;}
#nav li:hover li { float: none; font-size: 11px; }
#nav li:hover a { background: #f0e8d8; }
#nav li:hover li a:hover { background: #fff7e7; }
/* This is for sublevels in the drop down */
#nav li:hover ul li ul {display: none}
#nav li ul li:hover ul { display: block; }
#nav li ul li ul li { position: absolute; left: 125px; bottom: 0px; border-style: solid; border-width: 1px; border-color:purple; z-index: 1; }
</style>
</head>
<body>
<div id="nav">
<ul id="menu">
<li>Column 1
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</li>
<li> Column 2
<ul>
<li>Link 1</li>
<li>Link 2</li>
</ul>
</li>
<li>Column 3<li>
</ul>
</div>
</body>
</html>
Try these CSS rules for your sublevels in the drop down:
/* This is for sublevels in the drop down */
#nav li:hover ul li ul {
display: none
}
#nav li ul li:hover ul {
display: block;
position:absolute;
top:0;
left:100%;
}
#nav li ul li ul li {
position:relative;
display: block;
float: left;
border: 1px solid purple;
z-index: 1;
}
I'm trying to create a hover effect in my drop down menu but I can't figure out how to do it.
What I want to do is this:
instead of this:
My Code - You can also see it here, (updated version)
HTML:
<nav>
<ul>
<li>One
<ul>
<li>1.1</li>
<li>1.2
</ul>
</li>
<li>Two
<ul>
<li>2.1</li>
<li>2.2</li>
<li>2.3</li>
</ul>
</li>
<li>Three
<ul>
<li>3.1</li>
<li>3.2</li>
</ul>
</li>
<li>Four</li>
</ul>
</nav>
CSS:
nav {
float: left;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content:"";
clear: both;
display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
}
nav ul li:hover {
background-color: #000;
}
nav ul li a:hover {
color: #fff;
}
nav ul li a {
display: block;
padding: 25px 15px;
color: #6F0;
text-decoration: none;
}
nav ul ul {
border-radius: 0px;
padding: 0;
position: absolute;
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 40px;
color: #000;
}
Any help will be appreciated.
Working fiddle:
Change the styles for the below two:
nav ul li:hover {
border-bottom: 1px solid #000;
color: #000;
}
nav ul li a:hover {
color: #000;
}
And add:
nav ul li:hover li:hover{
background: #000;
}
In order to style the sub-menus.
The first (li:hover) you want to set a bottom border - you can change the width of this border from 1px to something more thick, say, 3px