html - 在窗口重新调整大小时居中重叠图像
问题描述
我有 2 个相同大小的图像需要完美重叠并在窗口重新调整大小时保持重叠。由于某种原因,设置位置:绝对;反转居中。这是到目前为止的代码,我已经用谷歌图片上的通用图片替换了我的图片。
<img src = "http://www.brittlestar.org.uk/wp-content/uploads/2014/02/300x300.gif" width = 50% height = auto style="position: relative; margin-left: auto; margin-right: auto; display: block;">
<img src = "https://www.leadheroes.com/wp-content/uploads/superforms/2018/07/883153652/5361c9b53077aa52c50fa005b15c6c4f%20(2)-300x300.png" width = 50% height = auto style = "position: absolute; z-index: 2; top: 50%; margin-left: auto; margin-right: auto; display: block;">
有谁知道如何解决这一问题?谢谢。
解决方案
我希望这就是你要找的:)
注意:请花时间阅读https://stackoverflow.com/help/how-to-ask,如果您不提供任何代码,这里的人将无法帮助您
html, body {
height: 100%;
}
div {
top: 50%;
position: relative;
margin-left: auto;
margin-right: auto;
width: 300px;
transform: translateY(-50%);
}
img {
max-width: 100%;
}
.overlap {
position: absolute;
top: 0;
left: 0;
z-index: 1;
}
<div>
<img src="https://via.placeholder.com/300x300">
<img class="overlap" src="https://www.leadheroes.com/wp-content/uploads/superforms/2018/07/883153652/5361c9b53077aa52c50fa005b15c6c4f%20(2)-300x300.png">
</div>
推荐阅读
- c# - 使用 Azure 管理 API 列出容器组失败并出现 System.Net.Sockets.SocketException
- java - 如何对上传到服务器的 java 代码运行测试
- oracle - 如何将整列 Oracle SQL 从另一个表插入到预先存在的行中?
- reveal.js - 我们如何为每张幻灯片(而不是每个片段)创建一个 PDF 页面?
- python - MySQL / Python Mysql 连接器仅在大型查询上没有结果
- google-app-engine - 从服务帐户进行身份验证。Google App Engine 中的程序化 IAP 身份验证失败
- windows - Windows 中的 Kafka 文件夹创建问题
- angular - mat-autocomplete FormGroup 需要输入问题
- javascript - 如何在 jQuery 上为音频文件运行下载命令
- macos - Catalina 是否支持 IBM MQ MacOS 工具包?