html - CSS3 z-index 问题

标签 html css z-index

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

我已经用图形说明了情况:

enter image description here

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

REDz-index:1; BLUEz-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-index。

所以,解决方案是:

#red{
    z-index:auto;
}

demo

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

相关文章:

html - 将 FlexBox div 并排放置

html - 我的 HTML/CSS 文件在 Nginx 上不同位置的路由有什么问题?

javascript - 拖放错误

css - 透明Div后面的可点击图像映射-在IE中工作

html - 您将如何修复这个常见的 IE Z-index 错误的不常见示例?

html - 在不使用z-index的情况下在另一个顶部显示div

javascript - 找不到指令 'carousel' 所需的 Controller 'ngTransclude'

html - 内联 block 溢出其容器的高度?

css - 如何将CSS规则应用于其中具有特定关键字的类?

html - SVG 的中心内容