0

I have a navbar ul with icons and another ul aligned in a fixed position to appear next to it with a label for each icon. When the user hovers over a li in the navbar, I want the corresponding li in the second ul to become visible, then become hidden again when the cursor leaves.

I have tried CSS solutions using :hover and jQuery ones using .show() and .hide(), but for some reason it isn't happening.

HTML:

<ul id="vnav">
   <li id="vis"><a class="vnavlink" href="#1"><span class="glyphicon glyph2 glyphicon-eye-open"  aria-hidden="true" aria-label="Vision"></span></a></li>
   <li id="val"><a class="vnavlink" href="#2"><span class="glyphicon glyph2 glyphicon-ok"  aria-hidden="true" aria-label="2"></span></a></li>
   <li id="foo"><a class="vnavlink" href="#3"><span class="glyphicon glyph2 glyphicon-ok" aria-hidden="true" aria-label="3"></span></a></li>
   <li id="dri"><a class="vnavlink" href="#4"><span class="glyphicon glyph2 glyphicon-ok" aria-hidden="true" aria-label="4"></span></a></li>
   <li id="eng"><a class="vnavlink" href="#5"><span class="glyphicon glyph2 glyphicon-ok"  aria-hidden="true" aria-label="5"></span></a></li>
</ul>

<ul>
   <li class="vbox" id="visbox">Vision</li>
   <li class="vbox" id="valbox">v2</li>
   <li class="vbox" id="foobox">v3</li>
   <li class="vbox" id="dribox">v4</li>
   <li class="vbox" id="engbox">v5</li>
</ul>

CSS:

#vnav {
list-style-type: none; 
text-decoration: none; 
position:fixed;
left:0;
top:350px;
z-index:1;
}

#visbox {
left:95px;
top:368px;
}

.vbox {
position:fixed;
z-index:1;
height:40px;
width:120px;
visibility:hidden;
}

#vnav:hover + #vbox {
visibility:visible;
}

Alternatively, here is one of my attempts at using jQuery for it:

$(document).ready(function() { 
  $('#visbox').hide();
});         

(NB. I also tried setting the default in the CSS as visibility:hidden or display:hidden)

$('#vis').hover(function(){
  $('#visbox').show();},
  function(){
  $('#visbox').hide();
});
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
geoman
  • 13
  • 4
  • I've tried to hack a fiddle together based on what you've given us: http://jsfiddle.net/axuj6089/ we obviously need more css. Two problems with your CSS attempt: `+` is the sibling selector and `vbox` is not a sibling of `#vnav`. Further more `vbox` is a class not an ID. Also try using `display:none` instead of `visability:hidden` and `display:block` instead of `visibility:visible;`. See this SO question for the differences: http://stackoverflow.com/questions/133051/what-is-the-difference-between-visibilityhidden-and-displaynone – Jon P Mar 10 '15 at 02:43
  • Thanks Jon - I did put vbox as a class when I tried it; I just typed it out wrong here. I managed to get the same result as you have achieved here before with css, but what I want is for each icon (i.e. each
  • ) to make just one label visible (i.e. just one
  • from the second
      ), rather than the whole
        rendering the whole second
          visible on hover, as happens here.
  • – geoman Mar 10 '15 at 11:13