jquery toggle dropdown menu problem (css)
i am trying to implement jquery's toggle method to make a dropdown menu, it actually works just fine, the only problem is that the dropdown menu pushed its parent container and it seems like it add some height to it, it kinda hard for me to say this but let me show some of my html and css
Html:
<div id="header_container">
<h1>This is Header</h1>
<div id="personal_menu">
<ul>
<li>
Welcome back user!
</li>
<li class="main_link">
<a href="#">My links</a>
<ul class="sublink" style="display: block;">
<li><a href="#">link 1</a></li>
<li><a href="#">link 2</a></li>
<li><a href="#">link 3</a></li>
<li><a href="#">link 4</a></li>
</ul>
</li>
<li>
<a href="#">Logout</a> </li>
</ul>
</div>
</div>
CSS
#header_container{
width:960px;
overflow:auto;
padding: 10px 15px;
margin: 0 auto;
}
#header_container{
background:#BED308;
height:218px;
-moz-border-radius: 0 0 40px 40px;
border-radius: 0 0 40px 40px;
}
#personal_menu{
overflow: auto;
position: relative;
right: 0;
top: 135px;
width: 100%;
}
#personal_menu ul, #main_menu ul{ list-style-type:none;}
#personal_menu ul{
float: right;
margin-top: 5px;
}
#personal_menu li{
float: left;
text-align: center;
}
#personal_menu li{
margin: 0;
padding: 3px 5px;
}
#personal_menu li a{
color: #fff;
text-decoration:none;
}
#personal_menu li a:hover{
text-decoration:underline;
}
#personal_menu ul li ul {
display: none;
position: absolute;
width: 160px;
border: 1px solid #ccc;
padding: 10px 0;
z-index: 1000;
}
and jquery:
$(function() {
$(".main_link").click(function(){
$(".sublink").toggle();
});
});
so when i click the main_link class, the toggled sublink stays inside the header container making my header scrollable, i have tried to put some z-index rule to my sublink because i figure that it need to be on top of everything else but still no luck, pl开发者_JS百科ease help.
Thanks
Try to delete overflow:auto. If you have undesired scroll, the problem must be here.
Which browser are you using?
Beware that IE7.0 has a z-index bug which causes something like your case, More info here: IE7 Z-Index Layering Issues
精彩评论