CSS 位置:相对出现在位置:绝对

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3538583/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:37:39  来源:igfitidea点击:

position: relative appearing over position:absolute

css

提问by Louis W

Having a strange issue in IE7. In a number of spots, I have a DIV which has position: absolute on it (faux dropdown) whenever there is something behind it which has position: relative the relative positioned item will show through the other div.

在 IE7 中有一个奇怪的问题。在许多地方,我有一个 DIV,它有 position: absolute (假下拉),只要它后面有东西有 position:relative 相对定位的项目将通过另一个 div 显示。

Relativly positioned item does not have any z-index set, while the absolutely positioned item (the one I want on top) has a z-index of 1000.

相对定位的项目没有任何 z-index 集,而绝对定位的项目(我想要在顶部的项目)的 z-index 为 1000。

http://skitch.com/louiswalch/dub5h/microsoft-windows-vista

http://skitch.com/louiswalch/dub5h/microsoft-windows-vista

回答by Pat

I suspect you've already tried it, but set a z-indexon your relatively positioned element that's lower than your absolutely positioned element's z-indexas the first test.

我怀疑你已经尝试过了,但是z-index在你的相对定位元素上设置一个低于绝对定位元素的 az-index作为第一个测试。

If that doesn't work, you need to make sure both elements are in the same stacking context. In IE, whenever you apply the positionCSS rule to an element, it generates a new stacking context within that element. That means that z-index will only be properly respected within that element's children and children in other stacking contexts withlower z-indexes may still stack above.

如果这不起作用,您需要确保两个元素都在同一个堆叠上下文中。在 IE 中,每当您将positionCSS 规则应用于元素时,它都会在该元素内生成一个新的堆叠上下文。这意味着 z-index 只会在该元素的子元素中得到适当的尊重,而具有较低 z-index 的其他堆叠上下文中的子元素可能仍会堆叠在上面。

In your case, you either need to put the dropdown and button in the same stacking context orapply z-index to the 2 elements that are generating their separate stacking contexts.

在您的情况下,您要么需要将下拉菜单和按钮放在相同的堆叠上下文中,要么将 z-index 应用于生成其单独堆叠上下文的 2 个元素。