不透明度不适用于叠加层

时间:2012-11-06 07:00:39

标签: css

我正在尝试创建一个弹出式叠加层,但我不能让蓝色叠加层变得不透明。红色显示出来。

<a href="www.google.com">hi</a>
<div class="dim">
    <div class="test">
        <div> test </div>
        <div> 2nd </div>        
    </div>
</div>​

.dim {
    height:100%;
    width:100%;
    position:fixed;
    left:0;
    top:0;
    background-color:red;
    opacity: 0.5;
}

.test {
    opacity: 1.0;
    border: solid;
    display: inline-block;
    background-color:blue;
    position: fixed;
    top: 50%;
    left: 50%;
    margin-top: -10px;
    margin-left: -10px;
}

Jsfiddle link

2 个答案:

答案 0 :(得分:1)

将html写为 -

<a href="www.google.com">hi</a>
<div class="dim">   
</div>
<div class="test">
    <div> test </div>
    <div> 2nd </div>        
</div>

Updated Fiddle

答案 1 :(得分:1)

简单的解决方法是复制和粘贴,将.dim放在.test。

之外

http://jsfiddle.net/NVa65/10/

来自

<a href="www.google.com">hi</a>
<div class="dim">
    <div class="test">
        <div> test </div>
        <div> 2nd </div>        
    </div>
</div>​

<a href="www.google.com">hi</a>
<div class="dim">

</div>
<div class="test">
    <div> test </div>
    <div> 2nd </div>        
</div>
​