...

View Full Version : Dropdown menu combined with image hover effect



Gnowoga
07-11-2008, 03:54 PM
Okay, so here's where I am having some troubles lately.

I built a simple enough menu that moved the background image when :hover, however I am also trying to combine this with a dropdown menu on hover. I am working out from Suckerfish dropdown ( http://htmldog.com/articles/suckerfish/dropdowns/ ), but frankly, I am not having much luck.

Here is my original menu ( working example: http://xpand2.no/tmp/savo/default.html ):


HTML:
<div id="menu">
<ul id="nav">
<li id="showroom"><a href="#1"><span>Showroom</span></a></li>
<li id="produkter"><a href="#2"><span>Produkter</span></a></li>
<li id="omsavo"><a href="#3"><span>Om Savo</span></a></li>
<li id="forhandlere"><a href="#4"><span>Forhandlere</span></a></li>
<li id="kontaktoss"><a href="#5"><span>Kontakt Oss</span></a></li>
</ul>

</div>

CSS:
div#menu{
/*placement*/
width:520px;
}
ul#nav{
width:520px;
float:left;
margin:0;
padding:0;
height: 23px;
list-style:none;
}
#nav li{
float:left;
height: 23px;
overflow: hidden;
}
#nav li a, #nav li a:visited{
display:block;
height: 23px;
}
li#showroom{
width:102px;
background: url(img/showroom.png) no-repeat;
}
li#produkter{
width:100px;
background: url(img/produkter.png) no-repeat;
}
li#omsavo{
width:91px;
background: url(img/omsavo.png) no-repeat;
}
li#forhandlere{
width:119px;
background: url(img/forhandlere.png) no-repeat;
}
li#kontaktoss{
width:108px;
background: url(img/kontaktoss.png) no-repeat;
}
li#showroom a:hover{
background: url(img/showroom.png) 0 -23px;
}
li#produkter a:hover{
background: url(img/produkter.png) 0 -23px;
}
li#omsavo a:hover{
background: url(img/omsavo.png) 0 -23px;
}
li#forhandlere a:hover{
background: url(img/forhandlere.png) 0 -23px;
}
li#kontaktoss a:hover{
background: url(img/kontaktoss.png) 0 -23px;
}
li span{
display:none;
}


Now the key is to implement a submenu, but this is where I am having trouble.

Here's suckerfish barebones( working example: http://xpand2.no/tmp/savo/dropdown.html ):


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<style type="text/css">
#nav, #nav ul { /* all lists */
padding: 0;
margin: 0;
list-style: none;
line-height: 1;
}
#nav a {
display: block;
width: 10em;
}
#nav li { /* all list items */
float: left;
width: 10em; /* width needed or else Opera goes nuts */
}
#nav li ul { /* second-level lists */
position: absolute;
width: 10em;
left: -999em; /* using left instead of display to hide menus because display: none isn't read by screen readers */
}
#nav li:hover ul, #nav li.sfhover ul { /* lists nested under hovered list items */
left: auto;
}
</style>
<script type="text/javascript"><!--//--><![CDATA[//><!--

sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

//--><!]]></script>
</head>

<body>

<ul id="nav">
<li><a href="#1"><span>Showroom</span></a>
<ul>
<li><a href="#">Oslo</a></li>

<li><a href="#">Bergen</a></li>
<li><a href="#">Stockholm</a></li>
<li><a href="#">KÝbenhavn</a></li>

</ul>
</li>
<li><a href="#2"><span>Produkter</span></a></li>
<li><a href="#3"><span>Om Savo</span></a></li>
<li><a href="#4"><span>Forhandlere</span></a></li>
<li><a href="#5"><span>Kontakt Oss</span></a></li>
</ul>

</body>
</html>


Can anyone help me with including both the image hover effect on the top items, and the submenu hover effect in the same menu? I am really stuck here :/ Any and all help is appreciated. I really don't want to do a dirty fix with positioning a div and using javascript to hide and show it. Want this the right way :)

It feels like I have tried most things. I either end up with just submenus or just hover effect. Also managed to get both at the same time, but then the image hovered over each submenu item. Overall I am pretty stuck and could use some fresh eyes.

Gnowoga
07-12-2008, 11:58 AM
wow. This was pretty sick, but I nailed it eventually, though with a few problems I was hoping someone would help with.

1. I can't get past the issue that all the submenu items has to be the same height as the main menu. This is a problem. (I fixed this is firefox, but it screwed everything in IE. It seems like IE does not like child selectors at all! ( div > a for example )

2. I would also like the mainmenu to be hovered all the time while using the submenu, but not that important.

3. The CSS probably needs a lot of cleaning. My eyes are going in all directions right now so give me a shout if you see some selectors that can be merged or optimized!

Here's is the working version:

http://xpand2.no/tmp/savo/dropdown.html

Edit: One more issue. The submenu does not show in IE 5.5. Any tips for this problem guys?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum