Related resources
If we have a small website with a simple horizontal menu, it can be very straightforward for visitors to use.
But, when a small website starts to grow, often we need to add additional menu items.
More items in a menu make it less easy to use, and less readable - it is good practise to keep the number of menu items below 7 items. If our menu consists of more elements, it starts to be confusing to our visitors.
What if we need a menu with 14 items (or even more)?
One solution to this is to create a Drop Down Menu. We want our menu be fast loading, lightweight, easy to implement, and SEO compatible so we are going to use CSS.
Building a drop down menu in Flash technology is not a good choice if we want our website to be accessible by search engines like Google. Besides, not all developers will have Flash.
Here you can learn how to create a simple, dynamic, fully customizable drop down menu using CSS and HTML.
1. Use HTML UL LI to build a list.
2. To your CSS add below code:
This will hide all sub elements. They are put to UL tag embedded in another UL tag.
See the HTML code at paragraph 1. Width of the menu element is set to 200 pixels.
3. Next we add this code.
We set hover behaviour to our LI elements embedded in first level of UL tag.
When we hover the LI element it will display previously hidden UL element of the second level (if they exist. In our example they are located in element number 3 and 5).
Property POSITION:absolute and LEFT:200px shifts the submenu 200 pixels right, and TOP: -4px place submenu items higher.
This example will not work with Internet Explorer 6, because this old fashioned browser doesn't understand :hover property connected with anything else than a elements.
It is a common Internet Explorer 6 error. There are many ways to fix it - one is to add the onmouseover function using JavaScript.
And that's it. Below is the demo. Download it and modify it to your needs.







Comments
Pablo
5th August, 2009 at 2:51pm
Very nice tutorial, thank you for sharing!
George
25th September, 2009 at 12:02pm
Perfect! - I've been looking for a tutorial this good for months. - Simple, gets the job done, and on top of that: JUST WORKS!. Thanks Munity Design.
Chris
20th October, 2009 at 6:38pm
This didn't work for me in IE 7
rob
3rd November, 2009 at 3:41pm
hi chris, what is problem you are getting? locally hosted example here is working. let us know problem and we will fix it.