【问题标题】:why is this modal's transparent background inherited by child element only in ie8?为什么这个模态的透明背景只在ie8中被子元素继承?
【发布时间】:2014-12-31 05:36:24
【问题描述】:

我正在尝试让我的网站在 ie8 上运行,我最初拥有的是 background-color:rgba(4, 4, 4, 0.8); - 这在其他浏览器上按预期工作,不幸的是 ie8 不适用于此,所以我使用下面的 css。 - 有谁知道如何避免子元素从父元素继承不透明度?

非常感谢。

我做了一个小提琴,但当我在 ie8 http://jsfiddle.net/up3uusxf/2/987654321@ 中打开它时似乎崩溃了

 <div id="overlay-modal">
      <div class="inner-modal">
        <p>Content in here</p>
      </div>
    </div> 

#overlay-modal
            {
                display:none;
                position:absolute;
                top:0;
                left:0;
                width:100%;
                height:100%;
                background-color:black;
                filter: alpha(opacity=80);
                        opacity: 0.8; 
                z-index:999;
            }
            .inner-modal
            {
                width: 400px;
                /*height: 270px;*/
                margin: 200px auto;
                background-color: white;
            }

【问题讨论】:

  • jsFiddle 编辑器在 IE8 中不起作用。您应该能够通过转到jsfiddle.net/up3uusxf/2/show 来查看输出
  • @lgupta 我看到了这就是为什么我提到它的 ie8,ie8 不支持 rgba
  • @user7167 那里有一些解决方案。检查第二个答案,如果它不起作用使用图像支持ie8。

标签: html css internet-explorer internet-explorer-8


【解决方案1】:

您需要让您的叠加层成为它自己的容器,其中包含内容之外的内容才能正常工作。

jsfiddle example here

HTML

<div id="overlay-modal">
    <div class="inner-modal">
        <p>Content in here</p>
    </div>
    <div class="justTransparentMask"></div>
</div> 

CSS

#overlay-modal {
    display:none;
    position:absolute;
    top:0;
    left:0;
    width:100%;
    height:100%;
    background-color:black;
    z-index:999;
}
.inner-modal {
    width: 400px;
    /*height: 270px;*/
    margin: 200px auto;
    background-color: white;
}
.justTransparentMask {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background: red;
    filter: alpha(opacity=80);
            opacity: 0.8; 
}

【讨论】:

  • 嗨,Szymon,谢谢你的回答,我对你想说的话有点困惑。但基本上,我的问题是内部模式变得透明,即使我不想让它透明,唯一应该是覆盖模式。
猜你喜欢
  • 2014-03-17
  • 2021-06-09
  • 1970-01-01
  • 2019-07-31
  • 2011-12-15
  • 2022-06-14
  • 1970-01-01
  • 1970-01-01
  • 2014-11-12
相关资源
最近更新 更多