css - css opacity 和 z-index 的问题

标签 css z-index opacity

在一个 div .frame 中,我有两个 div:.main 和 .bottom。 它们的位置相同,但 .main 具有更高的 z-index 值。 当鼠标在 .frame 上时,.main 的不透明度变为 0.5,因此当鼠标在 .main 上时,我们可以看到 .bottom。 Without visibility: hidden 当.main 的不透明度为0.5 时,如何隐藏内容.bottom?

我的 CSS 是:

.frame{
    position: absolute;
    top:20px;
    left:20px;
    width:100px;
}

.main{
    position: absolute;
    top:0px;
    z-index:2;
    max-width: 100%;
    background-color: red;
    width:100%;
}

.bottom{
    position:absolute;
    top:0px;
    z-index:1;
    width:100%;
}

.frame:hover .main{
    opacity:0.5;
}

和我的 html:

<div class="frame">
    <div class="main">main<br>main<br>main<br>main<br></div>
    <div class="bottom">bottom<br>bottom<br>bottom<br></div>
</div>

这里有一个 jsFiddle:http://jsfiddle.net/malamine_kebe/MNTcz/

最佳答案

将鼠标悬停在 .frame 元素上时,将 .bottom 元素的不透明度更改为 0。

添加此 CSS:

.frame:hover .bottom {
    opacity:0;
}

Fiddle

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

相关文章:

javascript - 有没有办法拥有不可变的 css 属性?

javascript - 使用 JavaScript 验证表单

css - 如何将图像放在 li 中的图像上(悬停时)更改其 z-index

html - 不同于 1 或 0 的 CSS 不透明度在 IE11 中不起作用

jquery - 打开模式时如何选择被阻止的内容?

jquery - 在 Jssor Gallery 中看不到我的图像

html - 容器中具有相同 z-index 参数的弹出叠加问题

html - 在 flexbox 悬停期间,我的文本隐藏在背景后面

html - 容器内内容的不透明度

html - 悬停区域在错误的位置激活,内容与中心对齐