The HTML
<div id="main">
<ul class="nyMenu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Tutorials</a>
<p>
<a href="#">PHP</a>
<a href="#">jQuery</a>
<a href="#">Cloud Computing</a>
</p>
</li>
<li><a href="#">Applications</a>
<p>
<a href="#">PHP Secure Login</a>
<a href="#">Sizzling jQuery</a>
<a href="#">Cooling Processor</a>
<a href="#">Jet Mail</a>
</p>
</li>
</ul>
</div>
The CSS
Here we will be using our Cross-browser Reset CSS
html,body,div,p,a,ul,li{margin:0;padding:0;border:0;outline:0;font-weight:inherit;font-size:100%;vertical-align:baseline;line-height:inherit;background:transparent;border-collapse:collapse;border-spacing:0;list-style:none}
body{font:400 13px Arial,Helvetica}
#main{margin:0 auto; width:1000px;}
/* nyMenu */
ul.nyMenu{border-top:1px solid #eee; float:left}
.nyMenu li{display:inline-block;position:relative;z-index:500;float:left}
.nyMenu li a {display:block; padding:9px 8px; text-decoration: none; color:#06b; font-size: 13px;}
.nyMenu li .hov{background:#eee;z-index: 499; position: relative}
.nyMenu li a.selected, .nyMenu li p a:hover{background-color:#069; color:#fff;}
.nyMenu li p {position:absolute; left:0; display:none; background:#eee; padding: 5px; z-index: 498;}
.nyMenu li p a {white-space:nowrap; padding:4px 8px;}
/* nyMenu ends */
The Javascript
var j = jQuery.noConflict();
j(function() {
j('.nyMenu li').hover(
function () {
j('p', this).show();
j('a:first',this).addClass("hov");
},
function () {
j('p', this).hide();
j('a:first',this).removeClass("hov");
}
);
});
Javascript with slide effect
var j = jQuery.noConflict();
j(function() {
j('.nyMenu li:has(p)').find('a:first').append(' ∨ ');
j('.nyMenu li').hover(function() {
j('p', this).slideDown('fast').show();
j('a', this).addClass('hov');
}, function () {
j('p', this).slideUp('fast');
j('a', this).removeClass('hov');
});
});
Your drop down menu will look same as above example in FF, IE7, IE8, IE9, Chrome, Safari, Opera.
Would like to know what is Cross-browser Reset CSS ?
Leave a Reply