Dropdown CSS issue - hidden list shows up when hovered over - html

my problem is that when I hover over the area where the hidden list is, it shows the hidden list. I only want it to show the hidden list when hovered over the 'Language' link on the dropdown menu. Why is it doing this, it's probably something blindingly obvious that I can't spot.
Cheers :)
EDIT: I've already tried using a fixed height for the #lang_bar. I also need the transitions to still work. I've already tried using the display:none and display:block; but that didn't work so I used visibility instead.
Any ideas?
HTML:
<div id="lang_bar">
<ul>
<li><strong>Language</strong>
<ul>
<li><strong>Maori</strong></li>
<li><strong>Tongan</strong></li>
<li><strong>Chinese</strong></li>
<li><strong>Japanese</strong></li>
<li><strong>Korean</strong></li>
</ul>
</ul>
</div>
#lang_bar {
font-family: 'Open Sans', sans-serif;
color: white;
padding-left: 152px;
text-transform: uppercase;
z-index: 40;
position: absolute;
padding-top: 2px;
top: 0;
}
#lang_bar ul ul li a {
padding-top: 3px;
padding-left:5px;
}
#lang_bar ul li ul li a:before {
content: '';
display:block;
right: 0px;
height: 2px;
bottom:117px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.2);
}
#lang_bar ul li ul li a:after {
content: '';
display:block;
right: 1px;
height: 2px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.6);
}
#lang_bar li, #lang_bar li ul {
text-decoration: none;
list-style-type: none;
}
#lang_bar ul {
list-style: none;
padding-left: 0px;
}
#lang_bar ul li {
float: left;
width: 100px;
text-align: left;
line-height: 21px;
}
#lang_bar ul li a {
display: block;
color: #FFF;
background: transparent;
text-decoration: none;
text-align: center;
}
#lang_bar ul li ul {
visibility: hidden;
font-size:12px;
opacity: 0;
}
#lang_bar ul li:hover ul {
opacity: 1;
visibility: visible; /* display the dropdown */
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#lang_bar ul li ul a:hover{
transition-duration: 0.6s;
background-color: rgba(255, 0, 0, 0.23);
}

I changed your css a little bit and here is the result
I used display:none and display: block in place of visibility, and everything is working as it should be.
http://jsfiddle.net/sy3qowxs/5/enter link description here
And here is your final CSS:
#lang_bar {
font-family: 'Open Sans', sans-serif;
color: #123111;
padding-left: 152px;
text-transform: uppercase;
z-index: 40;
position: absolute;
padding-top: 2px;
top: 0;
}
#lang_bar a:link{color:#333333;}
#lang_bar ul ul li a {
padding-top: 3px;
padding-left:5px;
}
#lang_bar ul li ul li a:before {
content: '';
display:block;
right: 0px;
height: 2px;
bottom:117px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.2);
}
#lang_bar ul li ul li a:after {
content: '';
display:block;
right: 1px;
height: 2px;
width: 100px;
position: absolute;
background: rgba(255, 255, 255, 0.6);
}
#lang_bar li, #lang_bar li ul {
text-decoration: none;
list-style-type: none;
}
#lang_bar ul {
list-style: none;
padding-left: 0px;
}
#lang_bar ul li {
float: left;
width: 100px;
text-align: left;
line-height: 21px;
}
#lang_bar ul li a {
display: block;
color: #FFF;
background: transparent;
text-decoration: none;
text-align: center;
}
#lang_bar ul li ul {
display: none;
font-size:12px;
opacity: 0;
}
#lang_bar ul li:hover ul {
opacity: 1;
display: block; /* display the dropdown */
-webkit-transition: all .25s ease;
-moz-transition: all .25s ease;
-ms-transition: all .25s ease;
-o-transition: all .25s ease;
transition: all .25s ease;
}
#lang_bar ul li ul a:hover{
transition-duration: 0.6s;
background-color: rgba(255, 0, 0, 0.23);
}

As an alternative to the display: none solution, for accessibility reasons you can use position:absolute and then move the hidden element off screen:
ul li ul {
position:absolute;
top:-1000px;
}
ul li:hover ul {
top:auto;
}

It should work with visibility, since it hides the element (like display: none) but doesn't remove it from the DOM
Here is a working example: Dropdown Menu
HTML
<ul class="menu">
<li class="menu-item"> Dropdown Menu
<ul class="submenu">
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
<li class="submenu-item">Link</li>
</ul>
</li>
</ul>
CSS
.menu-item {
position: relative;
}
.menu-item:hover .submenu {
visibility: visible;
opacity: 1;
}
.submenu {
position: absolute;
visibility: hidden;
transition: all .2s ease;
opacity: 0;
top: 100%;
}
.submenu-item {
padding: .4em;
}

What about just using the adjacent sibling combinator:
Change: #lang_bar ul li:hover ul
To: #lang_bar ul li a:hover + ul

To add to the previous answer, the reason this works when you use the display property instead of visibility is because display removes the element from the document flow, and other elements reflow in its place. Visibility, on the other hand, hides the element, but leaves the empty space as if it were still there. So when you used visibility: hidden, your list item looked like it just contained the text "Language" and the link, but the hidden ul was still there, and still hoverable. That's why when you hovered over where the list item should have been, it reappeared; technically, you were hovering over that first list item, because the sub menu was a child of it.
In general, I use display:block/display:none to toggle hiding and showing of items, rather than visibility. Typically the use case is that you want the element completely hidden from the page, and elements around it to reflow, and the display property will do that for you.

Related

HTML two hover Effects don't work

So I am creating a menu for a site but I can't get these two hover effects to work at the same time. I want that when I hover over the names the letters go brighter + the white block under the names should fade in (not for the active one) but I only get the first effect to work...
Here is the Jsfiddle to see. I appreciate all help :)
HTML:
<body>
<div id="cssmenu">
<ul>
<li class='active'><a href='#'><span>Home</span></a></li>
<li><a href='#'><span>Products</span></a></li>
<li><a href='#'><span>Company</span></a></li>
<li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
</body>
CSS:
#import url(http://fonts.googleapis.com/css?family=Open+Sans:700);
html {
background: url(img/bodybg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
#cssmenu {
background: rgba(51,51,51,0.5);
height: 0.3%;
text-align: center;
}
#cssmenu ul {
list-style: none;
margin: 0;
padding: 0;
line-height: 1;
display: block;
zoom: 1;
}
#cssmenu ul:after {
content: " ";
display: block;
font-size: 0;
height: 0;
clear: both;
visibility: hidden;
}
#cssmenu ul li {
display: inline-block;
padding: 0;
margin: 0;
}
#cssmenu ul li a {
color: #C8C8C8;
text-decoration: none;
display: block;
padding: 15px 25px;
font-family: 'Open Sans', sans-serif;
font-weight: 700;
text-transform: uppercase;
font-size: 14px;
position: relative;
-webkit-transition: color .25s;
-moz-transition: color .25s;
-ms-transition: color .25s;
-o-transition: color .25s;
transition: color .25s;
}
/*Hover Effekt */
#cssmenu ul li a:hover {
color: #FFFFFF;
}
#cssmenu ul li a:hover:before {
width: 100%;
}
#cssmenu ul li a:before:hover {
opacity: 100%;
}
/* Kleiner Block nach jeder Spalte */
#cssmenu ul li a:after {
content: "";
display: block;
position: absolute;
right: -3px;
top: 19px;
height: 6px;
width: 6px;
background: #E6E6E6;
opacity: .5;
}
/*"Effekt2"*/
#cssmenu ul li a:before {
content: "";
display: block;
position: absolute;
left: 0;
bottom: 0;
height: 3px;
width: 100%;
background: #FFFFFF;
opacity: 100%;
-webkit-transition: opacity 0.2s ease-in-out;
-moz-transition: opacity 0.2s ease-in-out;
-ms-transition: opacity 0.2s ease-in-out;
-o-transition: opacity 0.2s ease-in-out;
transition: opacity 0.2s ease-in-out;
}
/*Aktive Seite Schrift weiß und "Effekt2" aktive*/
#cssmenu ul li.active a {
color: #FFFFFF;
}
#cssmenu ul li.active a:before {
width: 100%;
}
Demo: jsfiddle.net/xwrfmtua
If you add hover to the #cssmenu ul li a:before class do you start to get what you want?
Something like this:
cssmenu ul li a:hover:before

CSS/HTML Drop Menu going away after moving mouse

I have a menu and some of my links have dropdown menus. Hovering over the link brings down the dropdown menu, but if I move my cursor onto the actual dropdown menu, the dropdown menu disappears.
Please help!
Here is the CSS and HTML of the actual menu:
CSS:
.menu ul {
color: #3d3d3d;
text-align: right;
float: right;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
.menu ul li {
font-family: LemonMilk;
font-size: 24px;
font-weight: bold;
display: inline-block;
margin-right: -4px;
position: relative;
padding: 15px 20px;
cursor: pointer;
-webkit-transition: all 0.2s;
-moz-transition: all 0.2s;
-ms-transition: all 0.2s;
-o-transition: all 0.2s;
transition: all 0.2s;
}
.menu ul li:hover {
color: #0096ff;
}
.menu ul li ul {
padding: 0;
position: absolute;
background-color: rgba(0,0,0, 0.5);
margin-top: 5px;
left: 0;
width: 150px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
.menu ul li ul li {
display: block;
color: #fff;
text-shadow: 0 -1px 0 #000;
font-size: 16px;
}
.menu ul li ul li:hover { background-color: rgba(0,0,0, 0.9); }
.menu ul li:hover ul {
color: #0096ff;
display: block;
opacity: 1;
visibility: visible;
text-decoration: none;
}
.menu ul li a {
color: #3d3d3d;
}
.menu ul li a:hover {
color: #0096ff;
}
.menu ul li ul li a {
color: #fff;
}
.menu ul li ul li a:hover {
color: #0096ff;
}
HTML:
<header>
<div class="wrapper">
<div id="clogo"></div>
<span class="menu">
<ul id="dropnav">
<li><a href="/forums/index.php" />Forums</a></li>
<li>Members
<ul>
<li>Member List</li>
<li>Staff List</li>
</ul>
</li>
<li>Donate<br>
<ul>
<li>Buycraft</li>
<li>Buy Credits</li>
<li>CL Plus</li>
</ul>
</li>
</ul>
</span>
</div>
</header>
Consider to use > selector in the CSS, so it only looks one level down the markup structure, no deeper. A demo that made similar to your style - http://jsfiddle.net/55nw4wmy/
.class ul li {
affects all levels of <li> inside.
}
.class > ul > li {
only affects the first level.
}
.class > ul > li > ul > li {
only affects the second level.
}
That way, you don't have to overwrite the rules continually. And for the drop down disappearing problem, see the comments in the demo link above.
The codes you shown work fine on my end, but from your code I suspect .menu ul li ul { margin-top: 5px; } could be the cause of such behavior. Currently it's working only because the first-level li have a bottom padding that is larger than 5px.
If by any chance the li in your homepage header doesn't have a bottom padding, then the top margin in the 2nd level ul will cause a 5px space between the li and the ul sublist inside it. When you move your mouse from the li to the sub list the mouse passes through that 5px space zone which doesn't belong to the list item and :hover loses its effect.
I would suggest changing that to .menu ul li ul { padding-top: 5px; }

Hovering over SPAN needs to change background of DIV on same level

I have created a fiddle for this: http://jsfiddle.net/Lux0ztyt/
When hovering over the SPAN (A,B,C,D, etc.), I need it to change the background to the same as when hovering the rest of the bar however I can't work out how to do it.
I know the problem is because the SPAN is at the END of all the elements but I am not able to change the positioning of this. How can it work with the positions staying as they are?
I have tried:
#my-list li span:hover ~ div {
/* background stuff */
}
And also:
#my-list li span:hover div {
/* background stuff */
}
And also:
#my-list li span:hover + div {
/* background stuff */
}
Any suggestions?
HTML:
<ul id="my-list">
<li class="100"><div style="width: 100%;"><label>100%</label></div><span>A</span></li>
<li class="85"><div style="width: 85%;"><label>85%</label></div><span>B</span></li>
<li class="95"><div style="width: 95%;"><label>95%</label></div><span>C</span></li>
<li class="85"><div style="width: 85%;"><label>85%</label></div><span>D</span></li>
<li class="95"><div style="width: 95%;"><label>95%</label></div><span>E</span></li>
<li class="80"><div style="width: 80%;"><label>80%</label></div><span>F</span></li>
<li class="90"><div style="width: 90%;"><label>90%</label></div><span>G</span></li>
<li class="95"><div style="width: 95%;"><label>95%</label></div><span>H</span></li>
</ul>
CSS:
#my-list {
list-style-type: none;
margin: 0px;
padding: 0px;
}
#my-list li {
display: block;
width: auto;
text-align: left;
position: relative;
margin: 2px 0px;
}
#my-list li span {
position: absolute;
left: 5px;
top: 0px;
color: #fff;
text-shadow: 1px 1px 1px #555;
font-size: 0.85em;
}
#my-list li div, #my-list li label, #my-list li span, #my-list li {
height: 30px;
line-height: 30px;
}
#my-list li div {
position: absolute;
background: #b02976;
left: 0px;
top: 0px;
width: 0px;
border-radius: 7px;
transition: width 1s, background-color 0.4s ease;
}
#my-list li div:hover {
background: #009e77;
transition: all 0.4s ease;
}
#my-list li div:hover > label {
display: block;
opacity: 1.0;
transition: all 0.4s ease;
}
#my-list li div label {
position: absolute;
right: 5px;
color: #fff;
font-weight: bold;
font-size: 0.7em;
opacity: 0;
transition: all 0.4s ease;
text-shadow: 1px 1px 1px #555;
}
Your code is almost working. The only thing you should change:
Handle the :hover on li rather than the div - then you have no problem:
change
#my-list li div:hover
to
#my-list li:hover div
and
#my-list li div:hover > label
to
#my-list li:hover div > label
The span element will send its :hover to the li - which then will colorize its div child as defined in the css.
http://jsfiddle.net/taqveyjs/1/
TimeDead's answer is correct in that you can't target a parent in CSS. I took a different approach though:
http://jsfiddle.net/austinthedeveloper/Lux0ztyt/2/
#my-list li div {
position: absolute;
background: #b02976;
left: 0px;
top: 0px;
width: 0px;
border-radius: 7px;
transition: width 1s, background-color 0.4s ease;
z-index:-1;
}
#my-list li:hover div {
background: #009e77;
transition: all 0.4s ease;
}
#my-list li:hover div > label {
display: block;
opacity: 1.0;
transition: all 0.4s ease;
}
The trick is to z-index the div so it is behind the li, masking your span. After that, you just update your hover classes to target the li instead of the div and everything works.
Sadly what your asking to do I'm not sure can be done strictly in CSS since in CSS you cannot select and change the parents background in this case the span is the child of the div there for cannot modify it's attributes.

Nav dropdown freaks out and shows different tabs

I'm trying to create a navbar (already done) with a dropdown, but the dropdown keeps spazzing out when I hover over it :(
I made a JS Fiddle of what I've accomplished so far, and I was hoping for some help!
http://jsfiddle.net/kkpp6/
I think it might be due to the display: none; I used in one of the ul's or possibly due to a stupid typo but I can't figure out where!
As well as this, I can't figure out how to make a sub-menu for my sub-menus that already exist.. (so the desc tab has a submenu of swim squad which will also have a sub-menu of other things).. How would I do that? I can't figure out where I would start!
Cheers for all the help in advance!
Try like this: LINK
CSS:
.nav-wrap {
background-color: #125CC1;
text-align: center;
}
ul.navigation-bar li a {
color: #FFFFFF;
background-color: #125CC1;
text-align: center;
padding: 6px;
font-size: 12px;
text-decoration: none;
text-transform: uppercase;
}
ul.navigation-bar li a:hover {
background-color: #06398F;
}
ul.navigation-bar {
text-align: left;
display: inline;
margin: 0;
list-style: none;
}
ul.navigation-bar li {
line-height:28px;
margin-right: -4px;
position: relative;
display: inline-block;
width: 120px;
font-weight: bold;
color: #FFFFFF;
background-color: #125CC1;
text-align: center;
}
ul.navigation-bar li ul {
padding: 0;
position: absolute;
top: 28px;
left: 0;
width: 120px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
-webkit-transiton: opacity 0.2s;
-moz-transition: opacity 0.2s;
-ms-transition: opacity 0.2s;
-o-transition: opacity 0.2s;
-transition: opacity 0.2s;
}
ul.navigation-bar li ul li {
background: #125CC1;
display: block;
color: #fff;
}
ul.navigation-bar li ul li:hover {
background: #06398F;
color: #fff;
}
ul.navigation-bar li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
Updated fiddle LINK
Multi-level dropdown menu LINK
On line 38, you set a list to display when the user hovers over a list item. This makes it visible, but also causes the entire menu to shift over so that you're no longer hovering over the list item that triggered that. If you use position:absolute on the list, it won't affect the other elements on the page:
ul.navigation-bar li > ul {
position:absolute;
}
JSFiddle: http://jsfiddle.net/P9SUg/
I also think its because of display:none;, instead of display:none; you should use visibility:hidden;.
and also add
ul.navigation-bar li > ul {
position:absolute;
}
You need to do lot of changes in CSS for making dropdown menu.
.nav-wrap {
background-color: #125CC1;
text-align: center;
}
ul.navigation-bar {
list-style-type: none;
margin: 0;
padding: 0;
}
ul.navigation-bar > li {
display: inline;
position:relative;
}
ul.navigation-bar > li > a {
display: inline-block;
width: 120px;
font-weight: bold;
color: #FFFFFF;
background-color: #125CC1;
text-align: center;
padding: 4px;
font-size: 12px;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: all 0.15s linear;
-moz-transition: all 0.15s linear;
-o-transition: all 0.15s linear;
transition: all 0.15s linear;
}
ul.navigation-bar > li > a:hover {
background-color: #06398F;
}
ul.navigation-bar ul {
display: none;
}
ul.navigation-bar li:hover > ul {
display: block;
position:absolute;
top:23px;
background-color:#ff00ff;
z-index:10;
width:100%;
list-style-type: none;
margin: 0;
padding: 0;
}
ul.navigation-bar li ul li a
{
list-type:none;
text-align: left;
font-weight:normal;
padding: 4px;
font-size: 10px;
text-decoration: none;
text-transform: uppercase;
-webkit-transition: all 0.15s linear;
-moz-transition: all 0.15s linear;
-o-transition: all 0.15s linear;
transition: all 0.15s linear;
}
ul.navigation-bar li ul li:hover
{
background-color:#000;
}
ul.navigation-bar li ul li:hover a
{
color:#fff;
}
FIDDLE DEMO

CSS dropdown menu element moving to left?

I'm having some troubles with this css menu of mine (I'm pretty new to the whole HTML/CSS thing, and so I pieced together some code from Wordpress and other websites). Everything works fine, except when the following occurs:
I hover over a menu item
The dropdown menu fades in
I move my cursor out of the dropdown menu
It moves to the very left side of the menu element and fades out
I don't understand why it moves to the left and doesn't stay in its intended position, and I need some help getting rid of it.
Here's the CSS code:
#import url(http://fonts.googleapis.com/css?family=Droid+Serif);
#cssmenu {clear: both; padding: 0; display: block; margin: 0; border: 0; float: left; z-index: 99999;}
#cssmenu ul, #cssmenu li {list-style: none; margin: 0; padding-left: 0;}
#cssmenu ul {position: relative; z-index: 99999; }
#cssmenu ul li { float: left; min-height: 1px; vertical-align: middle;}
#cssmenu ul li.hover,
#cssmenu ul li:hover {position: relative; z-index: 99999; cursor: default; opacity: 1;}
#cssmenu ul ul {visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 99999; width: 100%;}
#cssmenu ul ul li {float: none;}
#cssmenu ul ul ul {top: 0; left: auto; right: -99.5%; }
#cssmenu ul ul {bottom: 0; left: 0;}
#cssmenu ul ul {margin-top: 0; }
#cssmenu ul ul li {font-weight: normal;}
#cssmenu a { display: block; line-height: 1em; text-decoration: none; }
#cssmenu {
position: fixed;
top: 0;
left: 180px;
width:100%;
background: #020202;
border-bottom: 4px solid #08c1c3;
font-family: 'Droid Serif', serif;
font-size: 14px;
}
#cssmenu > ul { *display: inline-block; }
#cssmenu:after, #cssmenu ul:after {
content: '';
display: block;
clear: both;
}
#cssmenu a {
display: block;
background: #020202;
color: #CCC;
opacity: 1;
padding: 0 20px;
z-index: 99999;
}
#cssmenu ul ul {
border-top: 4px solid #08c1c3;
text-transform: none;
min-width: 190px;
float: left;
opacity: 0;
position: absolute;
left: 0;
visibility: hidden;
-webkit-transition: visibility 0s 0.4s, opacity 0.4s ease-in;
-moz-transition: visibility 0s 0.4s, opacity 0.4s ease-in;
-o-transition: visibility 0s 0.4s, opacity 0.4s ease-in;
transition: visibility 0s 0.4s, opacity 0.4s ease-in;
z-index: 99999;
}
#cssmenu ul ul a {
background: #020202;
color: #CCC;
border: 1px solid #08c1c3;
border-top: 0 none;
line-height: 1.25;
padding: 16px 20px;
z-index: 99999;
width: 150px;
}
#cssmenu ul li:hover > ul {
display: block;
opacity: 1;
-webkit-transition: opacity 0.4s ease-in;
-moz-transition: opacity 0.4s ease-in;
-o-transition: opacity 0.4s ease-in;
transition: opacity 0.4s ease-in;
visibility: visible;
}
#cssmenu ul ul li {
}
#cssmenu > ul > li > a { line-height: 48px; }
/* #cssmenu ul ul li:first-child > a { border-top: 1px solid #08c1c3; }
#cssmenu ul ul li:hover > a { background: #333; } */
#cssmenu ul ul li:last-child > a {
box-shadow: 0 1px 0 #08c1c3;
}
#cssmenu ul li:hover > a, #cssmenu ul li.active > a {
background: #333;
color: #08c1c3;
opacity: 1;
} /* Top level of menu */
#cssmenu ul li.has-sub > a:after {
content: "\00BB";
float: right;
margin-left: 5px;
}
#cssmenu ul li.last ul {
left: auto;
right: 0;
}
#cssmenu ul li.last ul ul {
left: auto;
right: 99.5%;
}
And here's an example menu:
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.html'>Home</a></li>
<li class='has-sub '><a href='#'>A</a>
<ul>
<li><a href='#'>A-a</a></li>
<li><a href='#'>A-b</a></li>
</ul>
</li>
<li class='has-sub '><a href='#'>B</a>
<ul>
<li><a href='#'>B-a</a></li>
<li><a href='#'>B-b</a></li>
<li><a href='#'>B-c</a></li>
</ul>
</li>
<li><a href='#'>C</a></li>
<li><a href='#'>About</a></li>
</ul>
</div>
You need to set position:relative on the list items for the default state, not for the hover state:
#cssmenu ul li {
position: relative;
}
Otherwise when you hover out the sub-menu is positioned relative to the menu container and not its parent
Updated fiddle