So, I've been 'collecting' CSS menus for a while now (another term would be 'borrowing', yet another would be 'blatantly ripping off'), to learn from them and to potentially reuse some of the leetness in my own projects.
Being an oldschool HTML purist, I love the idea of styled <ul>
s and <ol>
s, and the better menus and tab interfaces tend to use this method, for accessibility or semantic soundness or whatever reason. I mainly like the method because it keeps my HTML source nice and clean.
Now, I've actually refactored my collection of CSS menus to fit one 'master' markup pattern that I've extrapolated from the most flexible examples out there, such as the CSS Zen Garden. It looks like this:
<div class="menustyle">
<ul>
<li class="current"><a href="#" title="Page 1"><span>Home</span></a></li>
<li><a href="#" title="Page 2"><span>Toys</span></a></li>
<li><a href="#" title="Page 3"><span>About Us</span></a></li>
<li><a href="#" title="Page 4"><span>Contact</span></a></li>
</ul>
</div>
<span class="clearit" /><br />
(the 'clearit' span at the end is used to set clear:both
after menus that require it)
Anyway, I've seen variations on this markup on many sites, some with an extra enclosing <div>
, some using a different word than current
, some attaching the current
class to the <a>
tag rather than the <li>
, and some leaving out the inner <span>
. Everyone seems to have their own way of doing menu markup that's just a tiny bit different.
Anyway, after tinkering with a lot of menus, the above is what I've come up with, but I'm trying to figure out if there is an actual established best practice for this. I'd like to set up a simple CSS menu foundry at some point, and it would be nice to get some input on the markup before going any further.
EDIT: The question is not about Javascript menus. I know there are excellent scripted menus out there, and that they allow you to have submenus, more advanced animations and hover timing, shortcut keys, drop shadows, and everything else. But 90% of menus don't need those features, and are much better off using CSS for styling and hover effects.