What I am looking for is probably very easy to find, but I am pretty n00b, and I don’t know what to call it, so hoping to find some help here. I want a horizontal tabbed menu system which drops down on clicking.
When I Google for CSS-based tabbed menus I can find plenty of examples, but all of them are made with the assumption that they will open on hover, and most use Javascript or some conditional-type stuff or hacks that I don’t really understand yet. I am planning to learn Javascript (just ordered the Head First book) and want to design slicker stuff in the near future. But right now I need some simple menus and I really want to understand how/why the code works as opposed to just copying and pasting stuff into the right place and not knowing quite what to do when something goes wrong. I am new to CSS and trying to ease myself into it. I have a basic grasp of the purpose and concepts, and of specificity and inheritance, but I obviously have much to learn.
Here’s what I want: a series of tabs across the top of the site. Each tab will have a single sub-menu (no nesting) which will open on clicking (not on hover) and stay open until something else (one of the links, or another tab) is clicked. This should be easy, right (maybe I’m being naïve)? I would like to find working examples so I can digest the code and customize it visually. It just seems like everything I find is trying to do MORE than that, which I’d like to avoid for the moment. I am assuming that something this simple functionally could be deployed without scripting, and still be made to easily accommodate the IE6-ers.
I’ll confess I haven’t given deep consideration to “usability” here; it just seems like a reasonable way to do a menu…but maybe that has something to do with why I can’t locate examples of what I want.
True enough, Ray. The “best” CSS-only multi-level menus I know of are on Stu Nicholls’s site, and they are pretty intensive, with lots of extra markup and tricksy stuff. Not for the newb. Hell, I have trouble figuring out how some of them are functioning, and I’ve been doing this a while.
On my tut site, I split the difference: I used a JS “megamenu” and provided a link for the non-JS users (that’s you, Poes) to a plainer menu. Probably makes no one particularly happy…
Requiring a click will result in the vast majority of users not knowing this, and so missing your sub-menus. You are putting a barrier between the user and the sub-menus, as many will mouse over the menu and on seeing no drop-down / fly out , assume that only the items they can see are available. If these don’t interest them immediately, you’v elost them.
Time to rethink this idea, perhaps.
PS why do you think you found so many menus that didn’t require users to click to reveal the sub-menus…
The “best” CSS-only multi-level menus I know of are on Stu Nicholls’s site, and they are pretty intensive, with lots of extra markup and tricksy stuff
Hi Michael,
I don’t know if you are aware of it or not but most of those x-browser css only menus on Stu’s site were using invalid nested tables for IE6. The only reason they pass validation is because the IE comments hide the table from the validator.
He does not advocate using them anymore, a lot of people keep their old code examples for archive purposes.
As we all know IE6 is the only browser that chokes on li:hover hence the reason for the sfhover script for it only. Other than that it’s pure css for all other browsers.
Probably the best thing going for someone that does not want to script li:hover for IE6 would be Timo’s Float Drop Menu.
That was CSS Quiz #27 here and it was refined down to the final version after the quiz.
And when he did, Stu came up with a click menu. However, as someone mentioned before, these aren’t cross-browser (because not all browsers leave the cursor focus on the last-clicked item… namely Chrome and Safari).
POS, you’ll want a Sons of Suckerfish-style menu (if it’s a dropdown, I got a little confused) and the YuriKolovsky menu is a version of it, and then layer your JS on top of that later (as you do with ALL code anyway). HTML, then CSS, then JS. And, I know eruna was trying to keep things simple for an example, but the HTML will not have onmouseover stuff in it. The JS will be entirely separate.
The Sons of Suckerfish page is really where I learned how to do “a” dropdown menu.
However when you said something about tab-clicking, I thought Eric Watson or Ray H did something like that (no dropdowns, just tabs you click on) and so far as I know, this is cross-browser (relies on server refreshes or course, but you could always layer some Hijax/ajax over that if you want).
Hm, Shaun Rambaran has on his page a sort of setup that may appeal to POS. http://forge.co.tt/ This is all CSS and HTML, though I think he also has a JS layer on top of it. Only works with certain design limitations, but creative minds can work with that.
Alex Dawson has a page that does something with the :target CSS pseudoclass…
I dunno if I can keep up with DK’s “POS” moniker, makes me think of another term : )
As much as I admire Meyer’s pioneering work with CSS I’m afraid I would not recommend that menu. I doubt he would either today. It is using display:none/block for the hide and show method for the sub ul which from an accessibility standpoint is not good. Keyboard users and screen-readers are not able to tab through the sublist items since they are display:none;
Still trying to avoid Javascript for now, and do the click-to-open menus, just to see how they look and feel.
Click functions will typically fall under behavior which is a job for javascript.
There are some pure css ways to do what you are wanting but they will not be x-browser compatible. Those methods often give some ill effects as far as using the browsers back button along with them.
Have a look at This Recent Thread , but being a css newb as you said you are it may be to advanced for you. Secondly they are experimental and not really recommended to be turned loose on the web.
Let us know if you just want a simple css dropdown and we can surely help with that.