html - 不能使具有不透明属性的 div 子元素不透明

标签 html css

我正在制作一个弹出窗口,当它出现时,将页面的其余部分模糊为灰色,.cover正在处理页面覆盖。但是,我无法覆盖它的 opacity:0.6;用 !important 规则。我要里面的<div>变得不透明,父级变得透明。

HTML:

    <div id="cover">
        <div id="popup">
            <img src="EFTI_POPOVER2.png" alt="endurance films institute" id="pop-img">
            <button id="pop-but" onclick="location.href='http://endurancefilmsti.com/sales/'">
                <span id="#but-span">
                    <strong>YES!</strong>
                </span>SHOW ME THE FUTURE OF ENDURANCE SPORTS TRAINING</button>
            <a id="back" href="#">No Thanks, Continue Shopping</a>
            <a href="#" class="cancel">&times;</a>
        </div>
    </div>

CSS:

#cover{ 
    position:fixed; 
    top:0; 
    left:0; 
    background:rgba(0,0,0,0.6); 
    z-index:5; 
    width:100%; 
    height:100%; 
    display:none; 
    opacity:0.6;
} 
#pop-img {
    opacity: 1 !important;
}

最佳答案

您的.cover 之前必须关闭。如果将不透明度设置为 0.6,则子节点将具有相同的不透明度。增加 #popup z-index 以获得您想要的结果。

<div id="cover"></div>
<div id="popup">
    <img src="EFTI_POPOVER2.png" alt="endurance films institute" id="pop-img">
    <button id="pop-but" onclick="location.href='http://endurancefilmsti.com/sales/'">
        <span id="#but-span">
            <strong>YES!</strong>
        </span>SHOW ME THE FUTURE OF ENDURANCE SPORTS TRAINING</button>
    <a id="back" href="#">No Thanks, Continue Shopping</a>
    <a href="#" class="cancel">&times;</a>
</div>

关于html - 不能使具有不透明属性的 div 子元素不透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26955472/

相关文章:

javascript - 'production' 代码中不推荐使用 jQuery .css

javascript - 在 Ember 中如何使用 View 更改 css 属性然后查看它?

Jquery 里选择器

css - 如何更改 mdc-select 下拉箭头的颜色?

html - anchor 链接不可全宽点击

html - 在 aspx 页面的 html 中更改 Css 类名称

javascript - 如何识别 HTML 元素是否具有 AngularJS 行为?

html - CSS - IE6 溢出

html - 无法提供指向 Logo 的 anchor 链接

javascript - 如何从已加载的图像 (<img>) 创建 HTML 5 文件?