Can anybody give a reference or is it possible to create a menu entirely depending on
CSS
and not a single bit of javascript
?
The Requirement is a dropdown menu, which can have many children ( submenu )
.
Will anything if created like this will be cross browser compatible
?
Any help on this topic will be appreciated!.
EDIT
Thanks for all your inputs one more doubt
Can this be implemented rather than using ul li
say div span
combination as that may help me achieving a menu which won't change my current html structure!
I have just finished developing a CSS Menu for mobile devices, using absolutely ZERO Javascript. Basically, by applying the
tabindex="-1"
attribute to anything you want, you allow that element to react to the:focus
CSS property without actually being part of the tab order (so you can't reach that element by tabbing through). Applying this to the currently accepted solution:I removed the
<a>
tags (because now our drop-menus are CLICKABLE, we insert thetabindex
on whatever we want to click on and the CSS gets changed to this:Check out this Codepen for my Mobile Menu:
It is certainly possible to do drop-down menus in CSS only, and many sites are now using it.
What you won't get (yet) with CSS are any animated roll-outs, etc - the menu will just toggle between visible and hidden. If you want animated roll-outs, jQuery may be a better option. That said, CSS animation does exist. It is only implemented in one or two browsers, but you could add it to your stylesheet anyway; it won't break browsers that don't support it; they just won't get the animation.
Cross-browser compatibility for CSS menus is relatively easy, as long as you ignore IE6. IE7/8 can be made to work without too much fuss, but IE6 is badly broken for virtually all CSS-only menu techniques. If at all possible, try to avoid having to support IE6. Its an old browser, and really needs to be left to die in peace.
Others have already provided links to some good examples, so I won't repeat them here.
Check this out: http://www.cssplay.co.uk/menus/final_drop.html
Check this site : http://www.cssplay.co.uk/menus/ which have a lot of different menus with CSS only. A reference.
The trick is the
:hover
pseudo-class.Ok? So your entire submenu has to go inside the
<li>
of the main menu item it corresponds to. Then for the CSS:Do a bit of styling, and job done.
Edit: For another layer of menus, it's really simple. Use this CSS:
Note that I've replaced
.menu>li:hover
with.menu li:hover
. That tells the browser to find allli
elements below the main menu (not just immediate descendants) and show their submenu when hovering. I've also got rid of using the submenu class because it's not really needed if you're basing the CSS on descendants. This will let you add as many levels as you want.See if this helps http://www.howtocreate.co.uk/tutorials/testMenu.html
http://www.texaswebdevelopers.com/blog/template_permalink.asp?id=129