如何确保容器内的img
能够集中并正确地从移动设备扩展到桌面?这是一个demo on Codepen。缩放到移动,以便更好地理解问题用响应<img>填充div并集中位置
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。我想要图像完全填充容器
说实话,我是相当新了flexbox。我在波旁网格中使用了你的代码,但它不起作用。 – samsos