How to make menu still selected when it's no longer hovered?

Discussion in 'HTML & Website Design' started by eches, Nov 10, 2010.

  1. #1
    Hi everyone,

    I have a new website over at topelectronicreview.com and I try to figure out how to make category menu (horizontal) stays selected even when it's not hovered. I attach a screenshot to illustrate the menu behavior I intend to achieve.

    When I hover on the main menu (i.e. "car electronics"), it's selected and the sub menu shows up as well. However, when I move my cursor over the sub menu, the main menu is no longer selected.

    [​IMG]

    Menu behaviour that I want to achieve

    1. When I move my cursor over the sub menus, the associated main menu should stay selected.

    2. One flaw that I notice is the sub menu is pretty small, so when I accidentally move the cursor outside the sub menu, the sub menu disappears. The main menu and the sub menus should stay selected regardless of the cursor whereabouts (unless I hover on other main menu)

    Here's the js code

    startList = function() {
    if (document.all && document.getElementById) {
    navRoot = document.getElementById("nav");
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="LI") {
      node.onmouseover=function() {
      this.className+=" over";
        }
      node.onmouseout=function() {
      this.className=this.className.replace
          (" over", "");
       }
       }
      }
     }
    }
    window.onload=startList;
    Code (markup):
    html structure

    <div id="nav-wrap"><ul id="navbar"><?php wp_list_categories('exclude=21,41&show_count=0&title_li='); ?></ul></div>
    HTML:
    CSS code

    #nav-wrap {
    	position: relative;
    	font-size: 16px;
    	font-weight: bold;
    	color: #fff;
    	padding: 0px 15px;
    	margin: 0 auto; 
    	height: 75px;
    	background: url(images/nav-wrap1.jpg) repeat-x;
    	text-align: center;
    }
    
    #navbar {
    	position: relative;
    	margin: 0 0 0 -15px;
    	padding: 0;
    	height: 43px;
    	line-height: 43px;
    	text-align: center;
    	font-weight: bold;
    }
    #navbar li {
    	list-style: none;
    	float: left;
    	font-weight: bold;
    }
    #navbar li a {
    	display: block;
    	padding: 0px 14px 0px 10px;
    	text-decoration: none; 
    	color: #042842;
    	font-size: 11px;
            text-transform:uppercase;
    	font-weight: bold;
    }
    #navbar li a:hover {
    	color: #91e8fb; 
            background:#15669b;
    }
    #navbar li ul {
    	display: none; 
    }
    #navbar li:hover ul, #navbar li.hover ul {
    	position: absolute;
    	display: inline;
    	left: 0;
    	width: 100%;
    	margin: 0;
    	padding: 0;
            font-size:11px;
    	height: 32px;
    	line-height: 32px;
    	font-weight: bold;
    }
    #navbar li:hover li, #navbar li.hover li {
            float:left;
    }
    #navbar li:hover li a, #navbar li.hover li a {
    	color: #FFF;
    	font-size: 10px;
    
    }
    #navbar li li a:hover {
    	color: #FFF;
    }
    Code (markup):
    I know google is our best friend, but I have no idea what to look for. If anybody can enlighten me on how to do this (pointing me some references), I would be able to figure out myself.

    Any ideas?

    Thanks in advance
     
    eches, Nov 10, 2010 IP
  2. GWiz

    GWiz Peon

    Messages:
    359
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #2
    GWiz, Nov 10, 2010 IP
  3. lonerunner

    lonerunner Member

    Messages:
    184
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    48
    #3
    Yea just use superfish menu from first link GWiz gave you. Its easy to setup and do what you want.

    btw your site is not loading for me.
     
    lonerunner, Nov 10, 2010 IP
  4. shahilroyhere

    shahilroyhere Well-Known Member

    Messages:
    189
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    130
    #4
    Just remove this section from the code -

    This should do it all.
     
    shahilroyhere, Nov 10, 2010 IP
  5. eches

    eches Well-Known Member

    Messages:
    250
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Thanks guys! It works wonders :D Just need a little tweak and currently working out the compatibility issue between featured content gallery (FCG) and the superfish
     
    eches, Nov 11, 2010 IP