Html 下拉菜单,z-index 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16318413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dropdown menu, z-index problems
提问by user1505027
I've got a problem. I have a drop down menu, but the drop down list is always one layer behind the body although the z-index of menu is set to 999 and z index of body set to -999
我有问题。我有一个下拉菜单,但下拉列表总是在正文后面一层,尽管菜单的 z-index 设置为 999,正文的 z 索引设置为 -999
Please chceck http://www.w3dominik.com/x/finemoney/(the menu on top right, it says dropdown and should have 2 options, only 1 is now visible)
请检查http://www.w3dominik.com/x/finemoney/(右上角的菜单,它说下拉菜单,应该有 2 个选项,现在只有 1 个可见)
Thanks for help
感谢帮助
回答by ralph.m
This will fix it for you:
这将为您修复它:
#header_wrap {
position: relative;
z-index: 10;
}
You often need to set the z-index on the outermost parent (particularly in older versions of IE).
您通常需要在最外层的父级上设置 z-index(尤其是在旧版本的 IE 中)。
回答by Manish Sharma
Just add position: relative
, z-index won't work without position.
只需添加position: relative
,z-index 在没有位置的情况下将无法工作。
header ul {
display: inline-block;
float: right;
height: 30px;
z-index: 999;
position: relative;
}