How to Create Simple Drop Down Menu


Web designing and development offers multitude solutions and techniques to create nice drop down menu effect. It’s just a basic and simplest technique to create nice drop down menu.

Now the CSS for Styling:

ul.topnav {
list-style: None;
padding: 0 20px;
margin: 0;
float: Left;
width: 920px;
background: #222;
font-size: 1.2em;
background: Url(topnav_bg.gif) repeat-x;
}
ul.topnav li {
float: Left;
margin: 0;
padding: 0 15px 0 0;
position: Relative;
}
ul.topnav li a{
padding: 10px 5px;
color: #fff;
display: Block;
text-decoration: None;
float: Left;
}
ul.topnav li a:hover{
background: Url(topnav_hover.gif) no-repeat center top;
}
ul.topnav li span
{
width: 17px;
height: 35px;
float: Left;
background: Url(subnav_btn.gif) no-repeat center top;
}
ul.topnav li span.subhover
{
background-position: Center bottom; cursor: Pointer;
}
ul.topnav li ul.subnav {
list-style: None;
position: Absolute;
left: 0; top: 35px;
background: #333;
margin: 0; padding: 0;
display: None;
float: Left;
width: 170px;
border: 1px solid #111;
}
ul.topnav li ul.subnav li{
margin: 0; padding: 0;
border-top: 1px solid #252525;
border-bottom: 1px solid #444;
clear: Both;
width: 170px;
}
html ul.topnav li ul.subnav li a {
float: Left;
width: 145px;
background: #333 url(dropdown_linkbg.gif) no-repeat 10px center;
padding-left: 20px;
}
html ul.topnav li ul.subnav li a:hover {
background: #222 url(dropdown_linkbg.gif) no-repeat 10px center;
}

And a little bit of jQuery:

$(document).ready(function(){
$(“ul.subnav”).parent().append(“”);
$(“ul.topnav li span”).click(function() {
$(this).parent().find(“ul.subnav”).slideDown(‘fast’).show();
$(this).parent().hover(function() {
}, function(){
$(this).parent().find(“ul.subnav”).slideUp(‘slow’);
});
}).hover(function() {
$(this).addClass(“subhover”);
}, function(){
$(this).removeClass(“subhover”);
});
});

This solution is pretty straight forward and easy to implement.

+ There are no comments

Add yours