CSS only menu, click to disappear -
i have menu structured this:
<div class="nav"> <div class="drnav"> <ul class="ulmenu"> <li> <div class="menuheader">my home</div> <div class="menu-content"> <ul> <li><a href="">item1</a></li> <li><a href="">item3</a></li> </ul> </div> </li> <li> <div class="menuheader">my stuff</div> <div class="menu-content"> <ul> <li><a href="">item4</a></li> <li><a href="">item6</a></li> </ul> </div> </li> </ul> </div> </div>
my css setup when hover on menuheader element menu-content element displayed (i.e. display: inline). works fine want when click 1 of links in list item elements within menu-content menu (i.e. parent menu-content element) disappears. of course want without javascript. saw 1 example used pointer-events restricts use ie 11 , i'd support @ least ie 10 if not 9 well. suggestions on how work?
technically it's possible, it's ado nothing (hard use in practice):
.ulmenu .menu-content { display: none; } .ulmenu > li:hover .menu-content { display: inline-block; } .ulmenu > li .menu-content:target { display: none; }
<div class="nav"> <div class="drnav"> <ul class="ulmenu"> <li> <div class="menuheader">my home</div> <div class="menu-content" id="menucontent_1"> <ul> <li><a href="#menucontent_1">item1</a></li> <li><a href="#menucontent_1">item3</a></li> </ul> </div> </li> <li> <div class="menuheader">my stuff</div> <div class="menu-content" id="menucontent_2"> <ul> <li><a href="#menucontent_2">item4</a></li> <li><a href="#menucontent_2">item5</a></li> </ul> </div> </li> </ul> </div> </div>
besides, once close menu way reopen opening , hovering initial one.
important note:
i point out having :hover
based menu huge disadvantage compared having javascript
based menu. because more half of today's traffic coming touch devices (and don't hover on touch-device, you?) while less 1%
of traffic has javascript
disabled.
so, perhaps explain why ask pure css solution? practical use pure css had in past 8 years payment gateway page, javascript strictly off. but, other that?
i happen know way around css, never keen on trying transfer dom manipulations css, instead of leaving them javascript. after all, that's javascript for. use right tool job. job here dom manipulation. use javascript.
here's input
/label
solution described in comments. realized don't have checkboxes, can use :focus
state hide menu contents. it's still buggy, in sense click anywhere in page needed make :hover
work again closed menu. it's closest can css
or, @ least, that's think.
.menuheader input:focus + label, .menuheader label { display: none; } .menuheader:hover label { display: inline-block; } input.hidden { position: absolute; opacity: 0; pointer-events: none; }
<ul class="ulmenu"> <li> <div class="menuheader"> <div>my home</div> <input id="menucontent_1" class="hidden" type="text" /> <label class="menu-content" for="menucontent_1"> <ul> <li><a href="#menucontent_1">item1</a></li> <li><a href="#menucontent_1">item2</a></li> </ul> </label> </div> </li> <li> <div class="menuheader"> <div>my stuff</div> <input id="menucontent_2" class="hidden" type="text" /> <label class="menu-content" for="menucontent_2"> <ul> <li><a href="#menucontent_2">item4</a></li> <li><a href="#menucontent_2">item5</a></li> </ul> </label> </div> </li> </ul>
Comments
Post a Comment