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();
});
), rather than the whole
rendering the whole second
visible on hover, as happens here.