Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - Hover One Element, Change Visibility on Another

Tags:

css

HTML is as Follows

<ul id="master">
 <li class="has-sub">Item</li>
   <ul class="sub">
    <li>Sub One</li>
   </ul>
 </li>
</ul>

CSS is

.sub { visibility: hidden; }
#master .has-sub:hover > .sub { visibility: visible;} 

I pretty much took the approach from a site where this works, but on my adventure the hero fails. Badly. What am I doing wrong?

like image 433
NotaGuruAtAll Avatar asked Oct 18 '14 19:10

NotaGuruAtAll


2 Answers

Your HTML is invalid...you have closed <li class="has-sub">Item</li> too soon.

.sub {
    visibility: hidden;
}
#master .has-sub:hover > .sub {
    visibility: visible;
}
<ul id="master">
    <li class="has-sub">Item
        <ul class="sub">
            <li>Sub One</li>
        </ul>
    </li>
</ul>
like image 136
Paulie_D Avatar answered Oct 07 '22 07:10

Paulie_D


First your html is invalid please fix that And Try this Change your html to

  <ul id="master">
    <li class="has-sub">Item
        <ul class="sub">
            <li>Sub One</li>
        </ul>
    </li>
</ul>

  .sub {
    visibility: hidden;
}
#master .has-sub:hover > .sub {
    visibility: visible;
}

DEMO

like image 30
Harutyun Abgaryan Avatar answered Oct 07 '22 06:10

Harutyun Abgaryan