【发布时间】:2016-11-01 12:20:30
【问题描述】:
如何确保容器内的img 居中并从移动设备正确缩放到桌面?这是demo on Codepen。扩展到移动设备以更好地了解问题
HTML
<div class="image-container">
<img src="https://placeimg.com/470/310/people" alt="" />
</div>
CSS
.image-container{
width: 100%;
height: 500px;
max-height: 500px;
background: red;
overflow: hidden;
text-align: center;
position: relative;
display: block;
}
img{
height: auto;
width: 100%;
max-width: 100%;
position: absolute;
top: -50%;
left: 0;
}
我问这个是因为图像在移动设备上失去了高度并且看起来不正确。我有点像`background-size:cover。我希望图像完全填满容器
【问题讨论】:
标签: html css responsive-design