61

I'm using Bootstrap 2.3.1 http://twitter.github.io/bootstrap/index.html

So I'm using their 'dropdown-menu' class to create some simple quick use dropdown menus, but for some reason on IE7 they are appearing behind text and other elements on my site.

Test Link: http://leongaban.com/_projects/defakto/CDS/

I added z-index to my CSS, but still doesn't seem to do anything, please help!

.header .header-nav ul#nav-account ul.dropdown-menu,
.header .header-nav ul#nav-library ul.dropdown-menu {
    z-index: 10000;
}

IE9, Chrome, FF and other modern no headache browsers: enter image description here


IE7 >:(
enter image description here

HTML

<div class="header-nav">

<ul id="nav-account" role="navigation" class="pull-right">

    <!-- Language Dropdown Button -->
    <li id="language-btn">
        <a href="#" id="drop1" class="dropdown-toggle" data-toggle="dropdown">English</a>
        <img src="img/header-small-down-arrow.png" alt="grey triangle"/><!-- <span class="grey_triangle"></span>-->

        <!-- Language Dropdown Menu-->
        <ul class="dropdown-menu" role="menu" aria-labelledby="drop1">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">English</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Spanish</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">German</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Japanese</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#">Chinese</a></li>
        </ul>
    </li>

    <!-- User Dropdown Button -->
    <li id="account-btn">
        <a href="#" id="drop2" class="dropdown-toggle" data-toggle="dropdown">Logout</a>
        <img src="img/header-small-down-arrow.png" alt="grey triangle"/>
        <!-- <span class="grey_triangle"></span> -->

        <!-- User Dropdown Menu-->
        <ul class="dropdown-menu" role="menu" aria-labelledby="drop2">
            <li role="presentation"><a role="menuitem" tabindex="-1" href="http://google.com">Logout</a></li>
            <li role="presentation"><a role="menuitem" tabindex="-1" href="#anotherAction">Account</a></li>
        </ul>
    </li>
</ul>
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
  • Could you try `$('.dropdown-menu').appendTo($("body"));`? If it's not going to work you can try another class instead .dropdown-menu but it is going to fix the issue, I guess. – Ömer Faruk Almalı Apr 22 '13 at 16:22
  • Hmm just tried both those options, the jquery didn't do anything (but break the non-IE7 dropdowns) and I renamed .dropdown-menu to .dropdown-menu1 and still same issue :( – Leon Gaban Apr 22 '13 at 17:16
  • Does this answer your question? [How to make div go behind another div?](https://stackoverflow.com/questions/19561585/how-to-make-div-go-behind-another-div) – Liam May 04 '22 at 12:22

7 Answers7

93

Its a stacking context issue!

Even though you are using z-index on the dropdown, it is only relative to elements in the same stacking context. You need to add a z-index and a position to a parent element in order to get this to work. In this case I would recommend the header-top div

Community
  • 1
  • 1
Blake Plumb
  • 6,779
  • 3
  • 33
  • 54
27

You can only use z-index on positioned elements (relative, fixed/absolute), so try adding:

.header .header-nav ul#nav-account ul.dropdown-menu,
.header .header-nav ul#nav-library ul.dropdown-menu {
    position: relative;
    z-index: 10000;
}
Adrift
  • 58,167
  • 12
  • 92
  • 90
18

If increasing the z-index of the parent element(as mentioned in other answers) did not work for you, it could be that one of the parent elements has the following property:

overflow: hidden;

Try changing it to:

overflow: visible;

and see if it works.

el3ati2
  • 475
  • 3
  • 11
6

Just make overflow as inherit or Visible.

it will solve the problem.

overflow: visible !important;

It worked for me awesomely

Ronak Bokaria
  • 616
  • 6
  • 6
2

Check out the "append-to vs. append-to-body vs. inline example" on the newest version of UI-Bootstrap lib.

tiago
  • 195
  • 1
  • 7
1

I had the same thing happen when using

overflow-x: hidden;

On the parent element. Had to turn it off.

Joey Levy
  • 99
  • 7
-1

it's resolved by adding in menu CSS.

position: relative;
z-index: 10000;
Arun
  • 1,933
  • 2
  • 28
  • 46
ganesh pandey
  • 120
  • 1
  • 6