I am trying to create a category menu like this.
I have created this so far : http://jsfiddle.net/q5GcD/
The big menu should close only if i take mouse out of bigmenu div.
Also, i am unable to position the big menu correctly so that it overlaps the small menu button.
Html :
<div id="mydiv">Menu</div>
<div id="bigmenu">This is big menu</div>
Css :
#mydiv {
position:absolute;
top:10px;
left:50px;
height:50px;
width:200px;
background-color:#fff;
border:1px solid black;
}
#bigmenu {
position:absolute;
top:10px;
left:50x;
height:500px;
width:200px;
background-color:orangered;
}
script :
$(document).ready(function(){
$('#bigmenu').css("display","none");
$('#mydiv').hover(function(){
$('#bigmenu').css("display","inline");
},function(){
$('#bigmenu').css("display","none");
}
);
});
You don’t need javascript, you can do it with CSS only using the
:hoverdynamic pseudo-class.#bigmenushould be a child of#mydiv, not a sibling, to keep it active until you go out of#bigmenu(instead of just out of#mydiv).You don’t need absolute position too.
Demo: http://jsfiddle.net/q5GcD/1/
HTML
CSS
This line:
is telling the browser to apply the rule between the brackets for an element with
id="bigmenu", that is child (with>, the Child Selector) of an element withid="myDiv", when you are hovering (mouse on) it.In the case of a sibling, like in your original HTML code, you should have used
+, that is the Adjacent Sibling Selector.