html - 叠加图像在 Chrome/FF/Edge 中有效,但在 IE 中无效

标签 html css internet-explorer overlay

我使用以下方法叠加两个图像: Jsfiddle:https://jsfiddle.net/u6y92hmL/1/

HTML:

<div class="overlay-single">
  <img class="top" src=http://lorempixel.com/100/100/>
  <img class="bottom" src=https://placehold.it/300x200>
</div>

CSS:

.overlay-single {
  position: relative;
  text-align: center;
}

.overlay-single .top {
  position: absolute;
  top: 0;
  z-index: 1;
}

在 Chrome、FireFox 和 Edge 中,它可以完美地将顶部图像粘贴到底部图像的左上角。但在 Internet Explorer 中,顶部图像是左对齐的。

有什么方法可以让 IE 以同样的方式运行吗?

最佳答案

According to w3c , 当 left 为 auto 时,绝对定位的框将准确地出现在它没有定位时应该出现的位置,这意味着 IE 做错了,需要修复

添加一个内部包装器,使其表现为内联元素(根据内容调整大小),将其设置为相对位置,您将获得跨浏览器所需的结果。

.overlay-single { 
  text-align:center;
}
.overlay-wrapper { 
  position:relative;
  display: inline-block;
}
.overlay-single .top {
  position:absolute;
  top:0;
  z-index:1;
}
<div class="overlay-single">
  <div class="overlay-wrapper">
    <img class="top" src="http://lorempixel.com/100/100/">
    <img class="bottom" src="https://placehold.it/300x200">
  </div>
</div>

关于html - 叠加图像在 Chrome/FF/Edge 中有效,但在 IE 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37711103/

相关文章:

php - 为什么两个页面,100% 相同的代码,都包含相同的 style.css 却有不同的输出?

javascript - 在 IE11 中禁用浏览器缩放

javascript - Internet Explorer 不会读取对象属性

javascript - 位置 : absolute a div over Flash

html - Bootstrap/下拉按钮

html - 如何使 css 表格响应?

html - 框阴影在 HTML、CSS 中无法正常工作

html - 为什么在将内容插入 Div 容器时我的布局会中断 (HTML CSS)

css - 每次保存文档时如何编译LESS文件?

php - 以用户语言显示我的网站