Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dropdown menu combined with image hover effect

    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 ):
    Code:
    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 ):
    Code:
    <!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.

  • #2
    New Coder
    Join Date
    Jul 2008
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Last edited by Gnowoga; 07-12-2008 at 01:06 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •