z-index issue with twitter bootstrap dropdown menu

2019-01-17 09:44发布

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.

10条回答
甜甜的少女心
2楼-- · 2019-01-17 09:46

This will fix it

.navbar .nav > li {
z-index: 10000;
}
查看更多
来,给爷笑一个
3楼-- · 2019-01-17 09:46

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.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-17 09:47

IE 7 on windows8 with bootstrap 3.0.0.

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

fixed

查看更多
手持菜刀,她持情操
5楼-- · 2019-01-17 09:47

This worked for me:

.dropdown, .dropdown-menu {
  z-index:2;
}
.navbar {
  position: static;
  z-index: 1;
}
查看更多
做自己的国王
6楼-- · 2019-01-17 09:50

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.

查看更多
Bombasti
7楼-- · 2019-01-17 09:58

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

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

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

查看更多
登录 后发表回答