【问题标题】:CSS Double background in IE 7,8 [duplicate]IE 7,8中的CSS双背景[重复]
【发布时间】:2014-10-16 23:49:21
【问题描述】:

我有下一个带有 2 个背景图片的 div, 但图像在 IE 7 和 8 中不可见。

 <div class="media" style="background-image: url('/play_video.png'), url('/video.jpg')">
                        <span>Click to play video</span>
                    </div>

.media {    
    background-position: center, center;
    background-repeat: no-repeat;
    width:245px;    
    height:150px;
    cursor:pointer;
    text-align:left;
    position:relative;             
}
    .media span {        
        bottom: 0;
        left: 0;
        color: black;
    }

可以修复吗?

【问题讨论】:

  • 巧妙地使用多个 div 和 z-index 可以产生类似的效果。更大的问题是为什么要支持 IE7 或 8?

标签: css internet-explorer background-image


【解决方案1】:

Nether IE7 和 8 支持多个背景图片。 Source

为了社区,here's a workaround using positioning

HTML

<div class="media-back">
  <span>Click to play</span>
  <div class="media-play">
  </div>
</div>

CSS

.media-back {
  position:relative;
  height:300px;
  width:300px;
  background-image:url(https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcQIbNF1wUNRvdk13BTlt_KZ6HrspnBIpMIOXAkbHsioDTCxMT5r);
  background-position:center center;
  background-repeat:no-repeat;
  background-size:cover;
}
.media-play {
  position:relative;
  background-image:url(http://tympanus.net/PausePlay/images/play.png);
  background-position:center center;
  background-repeat:no-repeat;
  background-size:cover;
  width:15%;
  height:15%;
  margin:0 auto;
  top:50%;
  transform:translateY(-50%);
}
span {
  position:absolute;
  bottom:0;
  left:0;
  cursor:pointer;
}

这不是技巧,我不知道您要追求什么美学,但是您可以使用定位来伪造相同的效果。

【讨论】:

  • 提供一种解决方法可能会使这个答案更有用
  • Here is a more reputable source ;) - 带有固定链接
  • 而不是链接w3schools
  • 这是一个合法的答案。您不能“修复”IE7/8 的背景图像属性,但可以使用样式变通方法。我同意上面的@Kai-Quing,不过……为什么要支持 IE7 或 8?
  • 如果有帮助,我通常使用modernizr 并添加一个 .no-csstransitions css 选择器来处理较少的 IE 特定覆盖。但通常我编写 css 根本不需要这个。尽管如此,有时设计需要它。我认为这个答案没有错。我认为每个人都不需要解决这个问题。这就像问如何让闪光灯在 iPhone 上工作。它不起作用,所以继续。
猜你喜欢
  • 2018-11-08
  • 2023-03-24
  • 1970-01-01
  • 1970-01-01
  • 2013-11-10
  • 2021-04-20
  • 2021-06-08
  • 1970-01-01
相关资源
最近更新 更多