I’ve been working on the first new client page in about two years, mostly as a favor to a friend since I’m still on doctors orders not to be working – but in the process came up with a way of handling menu fly-outs that I’ve never seen before… I’ve dabbled with this approach in the past but I’ve never seen anyone else use it – and my former attempts had some issues because I was… well, even I overthink solutions to problems once in a while.
I’ve got a demo up here:
Overflow:hidden menu demo
The key part of the code is that rather than try to move the APO child menu, or play around with display:none – I set the parent LI to overflow:hidden… and set it to visible when hovered…
LITERALLY (cutting out all the fancy anchor and color code):
#mainMenu li {
position:relative;
float:left;
height:32px;
overflow:hidden;
}
#mainMenu li:hover {
overflow:visible;
}
#mainMenu li ul {
list-style:none;
position:absolute;
left:50%;
top:32px;
width:144px;
margin-left:-72px;
text-align:center;
}
#mainMenu li li ul {
top:0;
left:100%;
margin-left:0;
}
Is all I had to do for the first drop-down and all the sideways ones – this means that on child UL’s you can state their position:left once and not have to play with adjacent siblings or any of that. I just APO the menus where I want them, and hovering the LI shows them if present…
The directory for that demo is as always wide open:
Index of /codeExamples/menuDemo
Though nothing too fancy in there, the simple CSS, the demo page itself, and good old CSShover3.htc to slap legacy IE into rank and file.
I’ve also been testing this against pretty much every browser I can think of… and it seems solid. Lands sake it even works in iCab, Arora and WebPositive.
Has anyone seen this approach before? I’m curious because I never have, and it seems SO superior to the code I’ve seen for handling this in the past. It’s so… obvious an answer, I’m wondering why I’ve not seen it before.
… and for an old salt like me, something I’ve not seen before, especially when it comes to CSS, is a rare and special gift.