Mexzhouse Design Pte Ltd Singapore 10 Anson road, International plaza #29-18 Singapore 079903

Contact us for web design and development quotations

  Free Online Quotation

How to add a dropdown menu using only css.

lets say u want create menu with

<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>

then you want to have a dropdown inside one of the list, in this example i want to have it inside on class dropdown. which means when i mouse over class drop down my menu button come out.

<ul>
<li></li>
<li class="dropdown">
<ul>
<li></li>
<li></li>
<li></li>
</ul>
</li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>

now we need to add a styles to your unorder list and lists.

/* this is to clear your unorder list margin and padding */
ul { margin:0; padding:0; }

/* clear your list styles and give a right margin when float left */
ul li { margin:0 0 0 20px; padding:0; list-style:none; display:block; float:left; }

here is the interesting part. now you have a class call dropdown.
/* give a relative position for your li.dropdown */

ul li.dropdown { position:relative; }

/* hide your dropdown lists */

ul li.dropdown ul { display:none; }

/* show when mouse over class dropdown */

ul li.dropdown:hover ul { display:block; }

:) enjoy

This entry was posted in Blog and tagged Css, dropdown, menu, Web Design. Bookmark the permalink.

2 Responses to How to add a dropdown menu using only css.

  1. j says:

    no demo?

  2. SKunder says:

    Does not work.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>