【发布时间】:2019-08-09 07:53:24
【问题描述】:
如何使图像缩小以适应固定位置的弹性框模态?
当尝试下面的图像重叠页眉/页脚。它需要适用于高、宽和 IE 中的图像。
.modal-dialog {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.modal-content {
display: flex;
flex-direction: column;
height: 100%;
}
.modal-header {
background: red;
margin: 20px;
}
.modal-body {
background: green;
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin: 0 20px;
}
.modal-footer {
background: blue;
margin: 20px;
}
<div class="modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
header
</div>
<div class="modal-body">
<img src="https://via.placeholder.com/900x1200" />
</div>
<div class="modal-footer">
footer
</div>
</div>
</div>
</div>
注意这是一个简单的例子,我确实使用的是复杂的 SVG,而不是图像标签,所以我不能使用背景图像。
【问题讨论】:
-
img { width:100%; height:100%; } -
@dgknca 扭曲图像
-
object-fit:cover;? -
max-width:100%;max-height:100%? -
@dgknca 裁剪图像
标签: css internet-explorer flexbox microsoft-edge