Drop down menu <li> hover changing background image - css

I have a drop down menu and I'd like each main menu tab to change to a specific image while hovering over it with the mouse.
ul {list-style: none;padding: 0px;margin: 0px;}
ul li {display: block;position: relative;float: left;}
li ul {display: none;}
ul li a {display: block; text-decoration: none; color: #fff;}
ul li a:hover {}
li:hover ul {display: block; position: absolute;}
li:hover li {float: none;}
li:hover a {background-image:url(rf3.gif);}
li:hover li a:hover {background: #fec96b; color:#fff;}
<ul>
<li>Support</li>
<li>Web Design
<ul>
<li>HTML</li>
</ul>
</li>
<li>Content Management
<ul>
<li>Joomla</li>
</ul>
</li>
</ul>
I'd like tabs like 'Support' and 'Web Desing' to change to each of their unique images - they are different.
I tried adding a class to ex.
<li class="hover">Support</li>
but with no success.

Give those two list items a unique class name, and then specify the appropriate CSS for them.
CSS:
ul {list-style: none;padding: 0px;margin: 0px;}
ul li {display: block;position: relative;float: left;}
li ul {display: none;}
ul li a {display: block; text-decoration: none; color: #fff;}
ul li a:hover {}
li:hover ul {display: block; position: absolute;}
li:hover li {float: none;}
li:hover a {background-image:url(rf3.gif);}
li:hover li a:hover {background: #fec96b; color:#fff;}
li.support > a:hover { background-url(path_to_image_for_support.png); }
li.web-design > a:hover { background-url(path_to_image_for_web_design.png); }
HTML:
<ul>
<li class="support">Support</li>
<li class="web-design">Web Design
<ul>
<li>HTML</li>
</ul>
</li>
<li>Content Management
<ul>
<li>Joomla</li>
</ul>
</li>
</ul>

Use Javascript. Instead of class, use 'ID' and assign each one a number. Then create a Javscript function that will use:
document.getElementById('[line number]').style.backgroundColor = "[desired background color]";
Done.

Related

Can't get the hover in my menu bar to work

I can't get the hover in my menubar to work. The html and css is below. I can get the display: none to work by itself. I can get the hover to work by itself. They just won't work together. Not sure what I am doing wrong.
This is the html:
<nav>
<ul>
<li><img class="mainbar"src="images/logov6v2.png" width="175" height="150" padding="0" text-align="center" vertical-align="text-top">
<li id="menudrop" class="rightbar">Menu</li>
<ul data-toggle="">
<li>Account Settings</li>
<li>About Us</li>
<li>Contact</li>
</ul>
</li>
</ul>
</nav>
This is the css:
#menudrop.rightbar ul li a {
color: red;
display: block;
text-decoration: none;
}
nav ul li ul {
display: none ;
background: #5f6975;
position: relative;
top:100%;
}
nav ul li ul:hover li {
display: block;
}
Besides fixing some missing closing tags the main adjustment is to change this
nav ul li ul:hover li {
display: block;
}
into that
nav ul li:hover ul {
display: block;
}
As the nav ul li ul ist set to display:none; it's not possible to set a hover on it.
Adjusted in Fiddle
And without the image:
#menudrop.rightbar ul li a {
color: red;
display: block;
text-decoration: none;
}
nav ul li ul {
display: none;
background: #5f6975;
position: relative;
top:100%;
}
nav ul li:hover ul {
display: block;
}
<nav>
<ul>
<li id="menudrop" class="rightbar">Menu
<ul data-toggle="">
<li>Account Settings
</li>
<li>About Us
</li>
<li>Contact
</li>
</ul>
</li>
</ul>
</nav>

Main Menu Color Change

I am trying to target the header element of a drop down menu which I load in jfiddle here: http://jsfiddle.net/DZLtm/16/
I am trying to get it so when you roll over nav ul li it show black instead of red. Here are the lines that I would have thought would do it.
nav ul li {float: right; width: 172px; height: 35px; background-color: red;}
nav ul li:hover > ul {display: block; text-align: left; background-color: black;}
Here is the HTML:
<nav>
<ul>
<li>BUTTON IMAGE
<ul>
<li>Accreditation Client Login</li>
<li>Training Client Login</li>
<li>Training Registration</li>
<li>Guardian Tracking</li>
</ul>
</li>
</ul>
</nav>
Can someone please tell me why nav ul li:hover wont work and what is > ul have to do with it. When I remove it it breaks the menu. Thank you Frank!
Just add nav ul li:hover {
background-color:black;
}
http://jsfiddle.net/weissman258/DZLtm/17/

CSS Drop Down Navigation, 3rd level issue

I'm trying to get a 3rd level of flyout/dropdown on this CSS navigation menu. The second level works great, only shows when you're hovering over the right top level link. However, the 3rd level shows when you hover over the TOP level also. It should be hidden until you hover over the right dropdown link and then flyout to the right. I have the position correct, but I need it to hide until the right link is hovered on.
Here's the site I'm working on: http://174.37.160.21 (the 3rd tier is under Products).
Here's my CSS for the whole menu. I'm sure it's something really easy to spot but I've tried all that I can think of. I'm not a CSS wizard or anything.
.menu { height:32px; position:relative; z-index:100; }
.menu ul {padding:0;margin:0;list-style-type:none;}
.menu li {float:left;width:auto; padding-left:6px; padding-right:6px; position:relative;}
.menu ul li a { font-size:13px; }
.menu ul li ul li a { font-size:13px; }
.menu a, .menu a:visited {display:block; font-size:15px; text-decoration:none; color:#454545; height:30px; border:1px; padding-left:10px;}
.menu ul ul { visibility:hidden; position:absolute; height:0; top:20px; left:0; width:150px; }
.menu ul ul li { background:#272727; width:150px; text-align:left; padding-top:5px; padding-bottom:5px; }
.menu ul ul li:hover { background:#454545; }
.menu ul ul ul { visibility:hidden; position:absolute; height:0; top:0; left:150px; width:150px; }
.menu ul ul ul li { background:#272727; width:150px; text-align:left; padding-top:5px; padding-bottom:5px; }
.menu ul ul ul li:hover { background:#454545; }
.menu table {position:absolute; top:0; left:0; border-collapse:collapse;} /* style the table so that it takes no ppart in the layout - required for IE to work */
.menu ul ul a, .menu ul ul a:visited, .menu ul ul ul a, .menu ul ul ul a:visited { color:#fff; height:auto;}
.menu a:hover, .menu ul ul li:hover { }
.menu :hover > a, .menu ul ul :hover > a, .menu ul ul ul :hover > a {}
.menu ul li:hover ul, .menu ul a:hover ul, .menu ul ul li:hover ul { visibility:visible; }
Here's is my HTML Code:
<ul>
<li>Home
<li>About Us</li>
<li>Services
<ul>
<li>Residential</li>
<li>Commerical</li>
<li>Emergency</li>
<li>Maintenance</li>
</ul>
</li>
<li>Products
<ul>
<li>Garage Doors
<ul>
<li>Residential Garage Doors</li>
<li>Commercial Garage Doors</li>
</ul>
</li>
<li>Openers & Operators</li>
</ul>
</li>
<li>Online Store
<ul>
<li>Replacement Remotes</li>
<li>Keyless Entry</li>
<li>Gears & Sprocket Parts</li>
<li>Safety Beams</li>
<li>Lube & Grease</li>
</ul>
</li>
<li>Ask a Pro
<ul>
<li>Submit a Question</li>
<li>Newsletter</li>
<li>FAQ's</li>
<li>News</li>
<li>Seasonal Tips</li>
</ul>
</li>
</ul>
This is the part that makes the submenu visible:
.menu ul li:hover ul,
.menu ul a:hover ul,
.menu ul ul li:hover ul { visibility:visible; }
Now, I'm not sure what your markup is (I can only guess seeing .menu table and a:hover ul...), but with a standard list based markup, this part is too greedy:
.menu ul li:hover ul
This selects all ul elements that are in the li:hover all the way down the line, up to the very last one. I think you want to select only the direct descendant:
.menu ul li:hover > ul
All I changed was adding the > character. Demo: http://jsfiddle.net/dgUFw/
EDIT: Updated demo with the HTML you just posted: http://jsfiddle.net/dgUFw/1/
The .menu element was missing from your post, so I wrapped the whole thing in a <div class="menu"> and it seems to work fine.

Third-Level Menu Items Are Always Showing

I am making a horizontal menu that is three levels deep. It works as intended for the first and second levels. However, when you hover over any of the first or second level menus, the third menu items are displayed.
Even more so, all third level menu items that are within the first level menu are displayed (all of the second level submenus). I have no idea how to correct this (I do, but I can't figure out the combination of ul li...etc).
*I realize my CSS and html is sloppy (black ftw) - that is going to get fixed later. My main concern now is to get it working correctly.
#menu ul {
margin: 0;
padding: 0;
position:relative;
list-style: none;
width: 150px; /* Width of Menu Items */
border-bottom-style:solid;
border-width:2.3px;
border-color:black;
padding-left:0px;
/*background:url(./images/fillers/vvv.png);*/
}
#menu ul li {
/* position: relative; */
}
#menu li ul {
position: absolute;
left: 149px; /*Set 1px less than menu width */
top: 0;
display: block;
}
#menu li:hover ul {
display: block;
}
#menu li:hover ul {
visibility:visible;
}
#menu ul ul {
visibility:hidden;
}
/* Fix IE. Hide from IE Mac \*/
* html #menu ul li { float: left; height: 1%; }
* html #menu ul li a { height: 1%; }
/* End */
/* Make-up syles */
#menu ul, li {
margin: 0 0 0 0;
}
/* Styles for Menu Items */
#menu ul a {
display: block;
text-decoration: none;
color: white;
padding: 4px;
border: 2.3px solid black;
border-bottom: 0;
}
/* Hover Styles */
#menu ul li:hover, #menu ul li a:focus {
background-color:#5a5a5a;
color:white;
background:url(./images/fillers/vvv.png);
}
/* Sub Menu Styles */
#menu li ul a {
text-decoration: none;
color: white;
text-align:center;
padding: 4px;
border: 2.3px solid black;
border-bottom: 0;
}
/* Sub Menu Hover Styles */
#menu li ul a:hover {
color: white;
}
#menu li ul a.noLink:hover, #menu li ul a.noLink, #menu .noLink, #menu li ul .noLink, #menu li a.noLink {
color: grey;
}
/* Icon Styles */
#menu ul a.submenu {background: url("r_arrow.gif") no-repeat right; }
#menu ul a.submenu:hover {background: url("r_arrow.gif") no-repeat right;}
<div id=menu>
<ul id=menuList>
<li>
Tournaments
<ul>
<li>
2011
<ul>
<li> 1, 2, 3</li>
<li> 4, 5, 6</li>
<li> 7, 8, 9</li>
<li> 10</li>
</ul>
</li>
<li>
2012
<ul>
<li>Season 1</li>
</ul>
</li>
<li><a class="noLink">2013</a></li>
<li><a class="noLink">2014</a></li>
</ul>
</li>
<li>---
<ul>
<li>
2011
<ul>
<li>1, 2, 3</li>
</ul>
</li>
<li><a class="noLink">2012</a></li>
<li><a class="noLink">2013</a></li>
<li><a class="noLink">2014</a></li>
</ul>
</li>
<li><a class="noLink" name="submenu" class="submenu">Leagues</a>
<ul>
<li><a class="noLink">2011</a></li>
<li><a class="noLink">2012</a></li>
<li><a class="noLink">2013</a></li>
<li><a class="noLink">2014</a></li>
</ul>
</li>
<li><a class="noLink" name="submenu" class="submenu">---</a>
<ul>
<li>
<a class="noLink" name="submenu" class="submenu">2011</a>
<ul>
<li><a class="noLink">---</a></li>
</ul>
</li>
<li><a class="noLink">2012</a></li>
<li><a class="noLink">2013</a></li>
<li><a class="noLink">2014</a></li>
</ul>
</li>
</ul>
</div>
I figured this solution out:
#menu li:hover ul ul, #menu li:hover ul ul ul, #menu li:hover ul ul ul ul{
display:none;
}
#menu li:hover ul, #menu li li:hover ul, #menu li li li:hover ul, #menu li li li li:hover ul{
display:block;
}
I had the same issue - found the solution here and it worked for me
CSS Drop Down Navigation, 3rd level issue
You need to add an ">" between li:hover and ul
ie: li:hover > ul

css color effect in a list and popup menu

In firefox (this doesnt work at all in IE6) i have this code
<div class="menu">
<ul class="nav">
<li>Home</li>
<li>Software
<ul>
<li>Blah</li>
<li>Blah3</li>
<li>Blah</li>
</ul>
</li>
<li>Code Samples</li>
<li>Resume</li>
</ul>
</div>
using this css
ul.nav li:hover,
.nav a:hover
{
background-color:#606060;
color: white;
}
I have the menu text ("software") become white while the background becomes grey. However when i move my mouse down to the menu item the background continues to be grey but the next is no longer white! why? how can i fix this?
This should work:
ul.nav li:hover,
ul.nav li:hover a,
{
background-color:#606060;
color: white;
}
I'm not sure why but apparently you have to select the a element directly to change its color, otherwise it will be ignored.
Could be other rules interfering with your CSS, can't say without seeing everything. I recommend using Firebug to look at calculated CSS and CSS rules to see if it's doing what you expect.
You'd have to rework your css but if you are doing a basic menu submenu you can get it all working in IE and FF by wrapping the submenu in your 'a' tag.
<div class="menu">
<ul class="nav">
<li>Home</li>
<li><a href="software.html">Software
<ul>
<li>Blah</li>
<li>Blah3</li>
<li>Blah</li>
</ul>
</a>
</li>
<li>Code Samples</li>
<li>Resume</li>
</ul>
</div>
Some CSS which shouldn't require JS to to work in IE6. Not tested but should work. Note you also need to add styling and positioning for the subnav, but this still shows the basics.
.menu ul li a {
color: blue;
}
.menu ul li a ul {
display: none;
}
.menu ul li a:hover {
color: white;
}
.menu ul li a:hover ul {
display: block;
}
.menu ul li a:hover ul li {
}
.menu ul li a:hover ul li a {
color: black;
}
.menu ul li a:hover ul li a:hover {
color: red;
}
Then for each submenu you want after the first menu just add
.menu ul li a:hover ul li a ul {
display: none;
}
.menu ul li a:hover ul li a:hover ul {
display: block;
}

Resources