4

I have a CSS driven simple drop down menu that can appear in double rows on narrower screens.

When I activate the dropdown of one of the top row items the drop down appears at the same "Z" level as the bottom row.

I thought I've set the z-indexes as required but it isn't working in Chrome, Firefox, Safari or iPhone.

Here is a sample: http://jsfiddle.net/bNBp3/ - "Meat" has a dropdown attached.

<ul id="main-navigation">
    <li><a href="/" title="Go to the Home page"><span>Home</span></a>
    </li>
    <li><a href="/meat/" title="Go to the Meat page"><span>Meat</span></a>
        <ul>
            <li><a href="/meat/bacon/" title="Go to the Bacon page"><span>Bacon</span></a></li>
            <li><a href="/meat/ham/" title="Go to the Ham page"><span>Ham</span></a></li>
            <li><a href="/meat/pork/" title="Go to the Pork page"><span>Pork</span></a></li>
        </ul>
    </li>
    <li><a href="/vegetables/" title="Go to the Vegetables page"><span>Vegetables</span></a>
    </li>
    <li><a href="/about-us/" title="Go to the About Us page"><span>About Us</span></a>
    </li>
    <li><a href="/contact-us/" title="Go to the Contact Us page"><span>Contact Us</span></a>
    </li>
    <li><a href="/a-z/" title="Go to the A-Z page"><span>A-Z</span></a>
    </li>
</ul> 
ul#main-navigation {
    display:block;
    border-bottom:1px solid #ccc;
    margin:0 auto 0px auto;
    min-height:21px;
    padding:0;
    width:100%;
    z-index:11;
    clear:both;
}
ul#main-navigation li {
    display:block;
    float:left;
    list-style:none;
    margin:0 5px 0 0;
    padding:0;
    position:relative;
    z-index:12;
    min-height:22px;
    min-width:30%;
}
ul#main-navigation li a {
    color:#000;
    display:block;
    padding:2px;
    text-decoration:none;
    z-index:13;
}
ul#main-navigation li a.current, ul#main-navigation li a.section {
    color:#fff;
}
ul#main-navigation li ul {
    background:#eee;
    position:absolute;
    left:-1px;
    top:21px;
    display:none;
    overflow:hidden;
    padding:0px;
    z-index:14;
    width:100%;
    border:1px solid #ccc;
}
ul#main-navigation li ul li {
    display:block;
    float:none;
    margin:0;
    z-index:15;
    width:100%;
    border-bottom:1px solid #ccc;
}
ul#main-navigation li ul li a {
    background:#eee;
    display:block;
    color:#333;
    z-index:16;
    zoom:100%;     
}
ul#main-navigation li ul li a:hover {
    background:#fff;
}
ul#main-navigation li:hover {
    background:#eee;
    border-left:1px solid #ccc;
    border-right:1px solid #ccc;
}
ul#main-navigation li:hover a.current {
    background:#eee; color:#000;
}
ul#main-navigation li:hover ul {
    display:block;
}
1
  • I'm working on it right now, I think it has something to do with you not using <div> tags. Commented Aug 19, 2011 at 4:10

1 Answer 1

4

Just get rid of all the z-index values and it works fine:

http://jsfiddle.net/bNBp3/12/

Tested in Chrome and Firefox6.

Edit: It seems I forgot to remove the z-index from ul#main-navigation li ul in the demo and that's what makes it work, so just set it to any value 1 or higher.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Wesley, I only set z-index on ul#main-navigation li ul and it's all good. If anyone knows why it happened I'd be very interested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.