Reputation:
I've just turned my website into a responsive layout and along the way I've somehow managed to make my dropdown menus not work. When hovering over 'Drop-downs' they don't display unless I'm using position: relative. They worked before using position: absolute - but it seems they only work with position relative now. When using relative it uses the width which messes up the navigation bar.
Using relative: http://d.pr/i/tp5R
Using absolute: http://d.pr/i/j7r1
CSS for my sub-menu
div.left_first_header ul.sub-menu {
width: 125px;
top: 14px;
z-index: 2;
height: 100%;
position: absolute;
-webkit-border-radius: 0px 0px 4px 4px;
-moz-border-radius: 0px 0px 4px 4px;
background: url(images/drop_down_bg.jpg);
padding-left: 15px;
padding-right: 15px;
background-repeat: repeat;
}
jQuery for the drop down functionality
jQuery(document).ready(function ($) {
jQuery("ul.dropdown li").hover(function() {
$('ul:first',this).css('visibility', 'visible');
}, function() {
jQuery(this).removeClass("hover");
jQuery('ul:first',this).css('visibility', 'hidden');
});
});
My website
http://wpvault.com/kahlam/
Considering it's 4am I've probably made a really stupid simple mistake.
I apologise if I've missed anything.
Upvotes: 0
Views: 4666
Reputation: 9792
There is no need to use jQuery for this. Try using CSS :hover
<div class="left_first_header">
<ul class="dropdown">
Dropdown
<ul class="sub-menu">
<li>item</li>
</ul>
</ul>
</div>
CSS:
.left_first_header .sub-menu {
width: 125px;
top: 14px;
z-index: 2;
height: 100%;
position: absolute;
-webkit-border-radius: 0px 0px 4px 4px;
-moz-border-radius: 0px 0px 4px 4px;
background: url(images/drop_down_bg.jpg);
padding-left: 15px;
padding-right: 15px;
background-repeat: repeat;
display: none;
}
.left_first_header .dropdown:hover .sub-menu {
display: block;
}
CSS demo: http://jsfiddle.net/TZbfJ/
EDIT: But if you still want to use jquery, try this:
.left_first_header .sub-menu {
width: 125px;
top: 14px;
z-index: 2;
height: 100%;
position: absolute;
-webkit-border-radius: 0px 0px 4px 4px;
-moz-border-radius: 0px 0px 4px 4px;
padding-left: 15px;
padding-right: 15px;
background-repeat: repeat;
display: none;
background-color: blue;
margin-top: 4px;
}
.dropdown {
background-color: red;
position: relative;
margin: 20px;
}
JS:
$(function(){
$(".dropdown").mouseenter(function(){
$(this).find(".sub-menu").show();
}).mouseleave(function(){
$(this).find(".sub-menu").hide();
});
})
jQuery demo: http://jsfiddle.net/63hkm/
Upvotes: 2