0

我几乎和这个问题一样:

但我不能使用他的解决方案。我必须设置所有可见的东西。假设我有这个代码:

<body>
    some information
    <div style="position:fixed;width:100%;height:100%;background-color:green;z-index: 2;opacity: 0.7"></div>
    <div style='z-index:1;background-color:white;position:fixed'>
        test1
        <div style='z-index:3;background-color:red'>
            test2
        </div>

    </div>      
</body>  

我的观点是面具 div 在身体上,而父 div 。父 div 在身体上方。在父 div 中有一个子 div,它在面具和他的父母,当然还有身体。mask、parent 和 child 都是 position:fixed,body 是相对的。好吧,无论我更改它们的位置类型或 z-index,我都无法设置它们。仅当我没有设置父级的 z-index 时,孩子才会正确地覆盖面罩,但如果没有,它们都在面罩后面。

4

1 回答 1

1

为了z-index生效,必须定位元素。还要降低掩码的 z-index 并增加z-indextest1 的 z-index。我也建议不要内联样式,但是我怀疑这可能是示例。

<div style="position:fixed;width:100%;height:100%;background-color:green;z-index: 1;opacity: 0.7"></div>
<div style='z-index:2;background-color:white;position:fixed'>
    test1
    <div style='z-index:3;background-color:red; position:relative;'>
        test2
    </div>

</div>

工作示例:http: //jsfiddle.net/vQz6P/

于 2013-02-04T10:33:13.760 回答