html - CSS3 z-index 问题

标签 html css z-index

很抱歉提出这样一个“虚拟”问题,但我真的找不到解决方案。

我已经用图表说明了这种情况:

enter image description here

container内,有两个 sibling ( RED <div>BLUE <div> )。 两者都有 position: absolute;

REDz-index:1; 蓝色z-index:2;

RED 的 child (GREEN) 有 position:relative;z-index:99;

我想让绿色高于蓝色

谢谢!

更新1。这是 fiddle

http://jsfiddle.net/yn9z7/

最佳答案

解决这个问题的关键在 sudhAnsu63 链接的文章中:

New stacking contexts can be formed on an element in one of three ways:

When an element is the root element of a document (the element)

When an element has a position value other than static and a z-index value other than auto

When an element has an opacity value less than 1

但解释恰恰是相反。要将蓝色元素设置在红色和绿色之间,红色元素无法生成堆叠上下文。由于第二条规则,它正在生成堆栈上下文;它的绝对位置和 z 索引与 auto 不同。

所以,解决办法是:

#red{
    z-index:auto;
}

demo

关于html - CSS3 z-index 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18687287/

相关文章:

html - 浏览器和 z-index 问题

jquery - 以动态网格固定窗口大小显示的图像

javascript - 表单提交后的通知

html - 来自 img.shields 的 C++ 标志

css - 坐在背景后面的 Bootstrap 模态

动画时 z-index on::before 的 CSS 问题

javascript - 有没有办法将类添加到特定类的第一个单词?

html - 使用 CSS 放大或缩小图像之间是否存在性能差异?

javascript - Html5 和 Css 如何创建单独的 ul li 并将 <aside> 移到左侧

html - 如何使用 CSS 将整个表格右对齐?