Let me start with the CSS code, edit the colors and sizes to suit your websites needs:
ul {
font-family: Arial, Verdana;
font-size: 14px;
margin: 0;
padding: 0;
list-style: none;
}
ul li {
display: block;
position: relative;
float: left;
}
li ul {
display: none;
}
ul li a {
display: block;
text-decoration: none;
color: #ffffff;
border-top: 1px solid #ffffff;
padding: 5px 15px 5px 15px;
background: #1e7c9a;
margin-left: 1px;
white-space: nowrap;
}
ul li a:hover {
background: #3b3b3b;
}
li:hover ul {
display: block;
position: absolute;
}
li:hover li {
float: none;
font-size: 11px;
}
li:hover a { background: #3b3b3b; }
li:hover li a:hover {
background: #1e7c9a;
}
|
Next is the HTML code. It is structured as nested lists so that even displaying the HTML source code without any CSS style will render it with a useful structure.
<ul id="menu">
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a>
<ul>
<li><a href="#">The Team</a></li>
<li><a href="#">History</a></li>
<li><a href="#">Vision</a></li>
</ul>
</li>
<li><a href="#">Products</a>
<ul>
<li><a href="#">Cozy Couch</a></li>
<li><a href="#">Great Table</a></li>
<li><a href="#">Small Chair</a></li>
<li><a href="#">Shiny Shelf</a></li>
<li><a href="#">Invisible Nothing</a></li>
</ul>
</li>
<li><a href="#">Contact</a>
<ul>
<li><a href="#">Online</a></li>
<li><a href="#">Right Here</a></li>
<li><a href="#">Somewhere Else</a></li>
</ul>
</li>
</ul>
|
Another method:
First off, the CSS
Place the following CSS in between your < head > < / head > tags.
<style>
/*---- CROSS BROWSER DROPDOWN MENU ----*/
ul#nav {margin: 0 0 0 200px;}
ul.drop a { display:block; color: #fff; font-family: Verdana; font-size: 14px; text-decoration: none;}
ul.drop, ul.drop li, ul.drop ul { list-style: none; margin: 0; padding: 0; border: 1px solid #fff; background: #555; color: #fff;}
ul.drop { position: relative; z-index: 597; float: left; }
ul.drop li { float: left; line-height: 1.3em; vertical-align: middle; zoom: 1; padding: 5px 10px; }
ul.drop li.hover, ul.drop li:hover { position: relative; z-index: 599; cursor: default; background: #1e7c9a; }
ul.drop ul { visibility: hidden; position: absolute; top: 100%; left: 0; z-index: 598; width: 195px; background: #555; border: 1px solid #fff; }
ul.drop ul li { float: none; }
ul.drop ul ul { top: -2px; left: 100%; }
ul.drop li:hover > ul { visibility: visible }
</style>
|
and secondly, the HTML
Place the following HTML in between your < body > < / body > tags.
<ul id="nav" class="drop">
<li><a href="#">Home</a></li>
<li>About Us
<ul>
<li><a href="#">History</a></li>
<li><a href="#">Clients</a></li>
<li><a href="#">Testimonials</a></li>
<li><a href="#">Staff</a>
<ul>
<li><a href="#">George Orsmond</a>
<ul>
<li>Web Design</li>
<li>Graphic Design</li>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
<li><a href="#">Dave Macleod</a></li>
</ul>
</li>
<li><a href="#">FAQs</a></li>
</ul>
</li>
<li>Services
<ul>
<li><a href="#">Web Design</a></li>
<li><a href="#">Graphic Design</a></li>
<li><a href="#">Logo Design</a></li>
</ul>
</li>
<li>Products
<ul>
<li class="dir"><a href="#">Templates</a></li>
<li class="dir"><a href="#">Stock Images</a>
<ul>
<li><a href="#">Category 1</a></li>
<li><a href="#">Category 2</a></li>
<li><a href="#">Category 3</a></li>
<li><a href="#">Category 4</a></li>
<li><a href="#">Category 5</a></li>
</ul>
</li>
<li><a href="#">Featured</a></li>
<li><a href="#">Top Rated</a></li>
<li><a href="#">Resources</a></li>
</ul>
</li>
<li><a href="#">Gallery</a></li>
<li>Contact Us
<ul>
<li><a href="#">Contact Form</a></li>
<li><a href="#">How to get here</a></li>
<li><a href="#">View the map</a></li>
</ul>
</li>
</ul>
|
…and there you have it, a cross browser compatible and very customizable CSS Dropdown Menu. You can also add as many tiers as you like! This example has 3 tiers.
0 comments:
Post a Comment