R E C E N T     E N T R I E S

POSTED: Wednesday, September 16, 2009

CSS dropdown menu without javascripting or hacks

Here is a tiered CSS drop-down menu that works in IE 6, 7, and 8; Opera 9 and 10; Firefox 3.5.3.00; Flock 2.0 and 2.52; and Chrome 2.0.172.43 and 3.0.195.21
without hacks or javascripting and is accessible without using a mouse.  One downside is that it still uses images for the tabs and the sub-menus are only one level.  View source to download code.
 

Example:

Code:

<style type="text/css">
<!--
body,td,th {
 font-family: Verdana, Geneva, sans-serif;
 font-size: 100%;
 color: #666;
}
body {
 background-color: #fff;
 margin-left: 20px;
 margin-top: 20px;
 margin-right: 20px;
 margin-bottom: 20px;
}

a, a:hover, a:active, a:focus {
 outline:0;
 direction:ltr;
}
 
.wrapper {
 position:relative; height:25px;
}
 
.mainmenu {
 position:absolute;
 z-index:100;
 font-family:Verdana, Geneva, sans-serif;
 font-weight:normal;
 font-size:90%;
 line-height:25px;
 left:50%;
 margin-left:-303px;
 width:606px;
}

ul.menu {
 padding:0;
 margin:0;
 list-style:none;
 width:100px;
 overflow:hidden;
 float:left;
 margin-right:1px;
}

ul.menu a {
 text-decoration:none;
 color:#fff;
 padding-left:5px;
}
 
ul.menu li.list {
float:left;
width:250px;
margin:-32767px -125px 0px 0px;
background:url(images/top1.png) no-repeat left bottom;
}

ul.menu li.list a.category {
position:relative;
z-index:50;
display:block;
float:left;
width:120px;
margin-top:32767px;
background:transparent;
}

ul.menu li.list a.category:hover,
ul.menu li.list a.category:focus,
ul.menu li.list a.category:active {
 margin-right:1px;
 background-image:url(images/tophover1.png);
 background-repeat:no-repeat;
 background-position:left top;
}

ul.submenu {
 float:left;
 padding:25px 0px 0px 0px;
 margin:0;
 list-style:none;
 background-image:url(images/tophover1.png);
 background-repeat:no-repeat;
 background-position:left top;
 margin:-25px 0px 0px 0px;
}
 
ul.submenu li a {
float:left;
width:120px;
background:#369;
clear:left;
}

ul.submenu li a.endlist {
 background:url(images/bottom1.png);
}
 
ul.submenu li a.endlist:hover,
ul.submenu li a.endlist:focus,
ul.submenu li a.endlist:active {
background:url(images/bottomhover1.png);
}
 
ul.submenu a:hover,
ul.submenu a:focus,
ul.submenu a:active {
background:#900;
margin-right:1px;
}
-->


</style>


<div class="wrapper">
<div class="mainmenu">
<ul class="menu">
<li class="list">
 <a class="category" href="#Home">Home</a>
</li>
</ul>
<ul class="menu">
<li class="list">
 <a class="category" href="#about">About Us&nbsp;&nbsp;&raquo;</a>
 <ul class="submenu">
  <li><a href="#about1">About link 1</a></li>
  <li><a href="#about2">About link 2</a></li>
  <li><a href="#about3">About link 3</a></li>
        <li><a href="#about4">About link 4</a></li>
  <li><a class="endlist" href="#about5">About link 5</a></li>
 </ul>
</li>
</ul>
<ul class="menu">
<li class="list">
 <a class="category" href="#articles">Articles&nbsp;&nbsp;&raquo;</a>
 <ul class="submenu">
  <li><a href="#articles1">Articles link 1</a></li>
  <li><a href="#articles2">Articles link 2</a></li>
  <li><a href="#articles3">Articles link 3</a></li>
  <li><a class="endlist" href="#articles4">Articles link 4</a></li>
 </ul>
</li>
</ul>
<ul class="menu">
<li class="list">
 <a class="category" href="#news">News&nbsp;&nbsp;&raquo;</a>
 <ul class="submenu">
  <li><a href="#news1">News link 1</a></li>
  <li><a href="#news2">News link 2</a></li>
  <li><a class="endlist" href="#news3">News link 3</a></li>
 </ul>
</li>
</ul>
<ul class="menu">
<li class="list">
 <a class="category" href="#donate">Donate</a>
</li>
</ul>
<ul class="menu">
<li class="list">
 <a class="category" href="#contact">Contact</a>
</li>
</ul>
<!-- end mainmenu --></div>
<!-- end wrapper --></div>

Comments

1. can I pls have this code, I am a newbie in CSS, thanks a bunch
by tony

2. very useful
by madhavan ma

3. Hi!
I couldn't get it working. I put
the code and then finished it with
It didn't work. Could you help me please or suggest if I am doing something wrong please.
by Sandra

4. I am currently trying out your Dropdown menu on my site. It works great on Firefox, Opera, but it doesn't work well on IE when it comes to the hover part where it becomes a pop under every other element in the page. Is there a way you can fix this because I've tried changing the z-index and that doesn't work. My site is http://goldlilys.110mb.com/Goldlilys
by goldlilys
5. The menu works on your site when the page is set for IE8 standard but the menu drops under when set at IE7 or quirks mode. There is a CSS conflict and your site contains more javascripts than the law allows. I'll try to take your page apart and see what I can do to point you in the right direction.
by Mike

6. Ahh, nevermind. Found that the menu clashes with one of jquery UI scripts. The best solution is to disable that script when IE is found as the browser. Now works fine, but just ain't pretty.
by goldlilys
7.
That looks great and i will be able to use it. But, is there an easy way, without writting code, to make a tabbed panel, with 8 tabs like you can do in dreamweaver, for frontpage? i made one in dreamweaver, then copied the code into FP, but it didn't come up right. i also tried using css tab program and got the same results. This would be a great help for my site. thank you.
by Mark
8. I've been fooling around with this menu, and another from CSSplay, to work as a drop-line menu. For whatever reason, I cannot get the cursed thing to actually float the contents to the left so they line up on the same line instead of cascading downwards. Any suggestions? My code is very close to what is posted on this site.
by Azrael

9. thank's
by udon2u
10. Hi, i'm trying to use this menu as it's perfectly suited for a simple site i'm creating. However, I need to widen both the 'category' and 'submenu' elements. They are set at 100px but when I change them to 150px the hover effect displays and for all 3 submenus. If I change the widths (both) back to your default 100px everything works fine. I've tried messing with some of your margin settings but nothing happens to fix it. You can see this at http://www.littlepawzpetsitting.com/default.html
by simco
11. SIMCO!
I am having the same problem. Did you find a fix?
by jon
12. that really nice css menu...
by Deepak+Rajpal
13. I can NOT get any of the menus I've created to work. They work fine in the online sites like yours that I use to created them. But when I try to use them in a page they revert to lists.
Whatever I am doing wrong has got to be really, really simple. But I can't figure out what it is.
So, once I have a list how the h*** do I get the d*** thing to work in a real, life page?
If possible, please give simple clear directions for EVERY step that any idiot could follow. And remember, you're not dealing with just any idiot. I've been beating my head against this minor problem for days.
Thanks.
by LJS

14. really nice css drop down menu tutorial for learning...
by vectshare
15. Thank you it works well on my browser.
by Amy

16. Cool
by sandeep

17. hi,, im new bie in css im just asking were can put in css this code nothing guide to follow were can i place this code inside in css please help me and give me guide thank you
by proxy
18. FYI - This also works on Safari 5.0.5
by Charlie Kalech

19. Nice tutorial of css drop down menu!!!
by shivani

20. VERY EFFECTIVE EASY TO LEARN
by HEMENDER JHA

21. hey friend i new blogger i don't know how use this in blog templates please tell me how i use this in blog templates
by mohit
22. Thanks. Very usefull.
by Marjo

23. plz me send complete code
by sahil

24. good job
by fandi
25. Hey guys we are missing the images to make div circular at corners pls post them to
by kathayatnk

26. gr8 job..
by Abhishek Kumar
27. It would be helpful if you walked through the code, or explained how it is able to work in IE 6 without Javascript. I'm having a hard time deciphering what exactly makes it different; is it that it still uses the a tag for hovering and neg/pos margins for hiding and showing the dropdown content? Thanks for the effort.
by Tiffany




Name
URL
Email
Email address is not published
Remember Me
Comments

CAPTCHA
Write the characters in the image above