1

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, please help.

Thanks

littlechad
  • 1,202
  • 17
  • 48

2 Answers2

1

Try to delete overflow:auto. If you have undesired scroll, the problem must be here.

Arsen K.
  • 5,494
  • 7
  • 38
  • 51
  • i have removed over flow auto on every container that has the rule, still no luck – littlechad Jun 05 '11 at 07:09
  • please, give a link for your menu – Arsen K. Jun 05 '11 at 07:32
  • @littlechad: I took your code to jsfiddle, removed the overflow:auto as @Webars said, your overflow seems to be gone and your menu now flows out of the header_container. http://jsfiddle.net/robx/xAGsG/ – robx Jun 05 '11 at 07:38
  • hmm, alright, i will tested this out, will get back at you guys will an update, thanks – littlechad Jun 05 '11 at 07:50
  • thanks guys, it turn out to be that there are other container that causing the toggle doesn't work the one wraps the header_container has an overflow:auto in it, and yes this solve the problem thanks a lot – littlechad Jun 05 '11 at 07:56
1

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

Community
  • 1
  • 1
Mo Valipour
  • 13,286
  • 12
  • 61
  • 87