63

I'm using twitter bootstrap dropdown menu in a fixed navbar at the top of my page.

It all works fine but am having issues with the drop down menu items showing behind other page elements rather than in front of them.

If I have anything on the page with position: relative (like jquery ui accordion, or a google chart) then the drop down menu shows behind it. Tried changing the z-index of the dd menu and of the nav-bar, but doesn't make any difference.

The only way I can get the menu to sit above the other content is to change the content to position: fixed; OR z-index: -1; -but both of these solutions cause other problems.

Appreciate any help you can give me.

I think this is probably some standard issue with CSS positioning that I've misunderstood, so haven't posted any code, but can do if needed.

Thanks.

Arnaud
  • 7,259
  • 10
  • 50
  • 71
Leon
  • 1,793
  • 2
  • 18
  • 20
  • See my answer at http://stackoverflow.com/questions/16149701/bootstrap-dropdowns-menus-appearing-behind-other-elements-ie7/36063349#36063349 – tiago Mar 17 '16 at 14:27

16 Answers16

60

Just realized what's going on.

I had the navbar inside a header which was position: fixed;

Changed the z-index on the header and it's working now - guess I didn't look high enough up the containers to set the z-index initially !#@!?

Thanks.

Arnaud
  • 7,259
  • 10
  • 50
  • 71
Leon
  • 1,793
  • 2
  • 18
  • 20
  • 16
    I had a similar issue that turned out to caused by "overflow: hidden" on a parent div. The solution was easy for me since, after reviewing it, I determined that I didn't need the overflow: hidden anymore so I removed it. – Scott Forsyth May 21 '13 at 13:46
  • 2
    @ScottForsyth-MVP I skimmed past your comment thinking.. overflow:hidden - that's not my issue - mine is all about z-index. So I went to the MDN page on stacking contexts (highly recommend) and went through my site meticulously setting positions and correct z-indices. Still the menu was being cut off. Then I noticed overflow:hidden in the css inspector and it reminded me of your comment - and that was it! – Julian Mann Dec 02 '15 at 16:11
  • Although I have a slightly different structure in the DOM and elements, what made the solution for me in the end was changing the z-index of the element that contained the dropdown element(s). Thanks! – TheCuBeMan Jun 28 '16 at 08:32
  • 1
    @ScottForsyth-MVP Thanks! your comment saved my live :D – ikhsan Feb 23 '19 at 20:33
16

IE 7 on windows8 with bootstrap 3.0.0.

.navbar {
  position: static;
}
.navbar .nav > li {
  z-index: 1001;
}

fixed

10

Ran into the same bug here. This worked for me.

.navbar {
    position: static;
}

By setting the position to static, it means the navbar will fall into the flow of the document as it normally would.

Johanna Larsson
  • 10,531
  • 6
  • 39
  • 50
rdoll
  • 101
  • 1
  • 2
6

This will fix it

.navbar .nav > li {
z-index: 10000;
}
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
parkerproject
  • 2,138
  • 1
  • 17
  • 14
4

In my case in addition to z-index I had to set overflow: visible in parents elements

crg
  • 4,284
  • 2
  • 29
  • 57
3

I had the same problem and after reading this topic, I've solved adding this to my CSS:

.navbar-fixed-top {
    z-index: 10000;
}

because in my case, I'm using the fixed top menu.

Fernando Vieira
  • 3,177
  • 29
  • 26
2

Solved by removing the -webkit-transform from the navbar:

-webkit-transform: translate3d(0, 0, 0);

pillaged from https://stackoverflow.com/a/12653766/391925

Community
  • 1
  • 1
Luke Ollett
  • 316
  • 2
  • 16
2

Still the issue with Bootstrap v3, navbar and dropdown have same z-index ;-( I just increased .dropdown-menu z-index to 1001.

Thomas Decaux
  • 21,738
  • 2
  • 113
  • 124
  • I just increased .dropdown-menu z-index to 1001. The solution is to increase this value. Sorry for my bad english ^^ – Thomas Decaux Aug 24 '13 at 15:35
  • ahh .. then I misunderstood you, sorry. You might consider a slight clarification in your answer (like you did in your comment :-) – kleopatra Aug 24 '13 at 16:12
2

Just give

position: relative; 
z-index: 999;

to the navbar

1

This fixed it for me:

.navbar-wrapper {
  z-index: 11;
}
JochenJung
  • 7,183
  • 12
  • 64
  • 113
1

Solved this issue by removing transform: translateY(50%); property.

kabangi julius
  • 2,709
  • 2
  • 16
  • 25
0

This worked for me:

.dropdown, .dropdown-menu {
  z-index:2;
}
.navbar {
  position: static;
  z-index: 1;
}
dessalines
  • 6,352
  • 5
  • 42
  • 59
0

I had the same problem, in my case because i forgot this in my NavBar style: overflow: hidden;

Vanderley Maia
  • 465
  • 5
  • 7
0

I ran into a situation where a button with a Bootstrap drop down was embedded in a DataTables row. In that instance, I had to remove fixedColumns: true in the settings because that was injecting a position: sticky into the element style.

Did not work:

$(document).ready(function () {
        var table = $('#order').DataTable({
            fixedColumns: true,
            fixedHeader: true, ...

Did work:

$(document).ready(function () {
            var table = $('#order').DataTable({
                fixedHeader: true, ...
gbc
  • 8,455
  • 6
  • 35
  • 30
0

I'm late to the party here but for anyone using the bootstrap sticky-top class beware that it's z-index is higher than what is defined for the dropdown so anything within it will bleed through the dropdown's menu.

https://github.com/twbs/bootstrap/issues/31747

This was my scenario and the other answers here that referenced position: sticky put me onto it.

Christopher King
  • 1,691
  • 23
  • 28
0

In my case, this was caused because I had a CSS animation with transform operations applied to a parent <div>. I worked around the problem by moving the animation to a different element.

Allen Ellis
  • 269
  • 2
  • 9