【发布时间】:2015-07-15 09:09:04
【问题描述】:
我希望图像填充窗口大小/视口的宽度或高度。
为了更好地了解我想要做什么,i’ve created an example on codepen - 请查看并调整预览大小。 它在 safari 中运行良好,但 chrome 和 firefox 似乎有问题。图片忽略了 max-height 属性并溢出了 flex-item 尺寸。
有什么建议可以在 chrome 和 firefox 中完成这项工作吗?
html,
body {
height: 100%;
}
.flex-container {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
background: green;
}
.flex-item {
max-width: 100%;
max-height: 100%;
}
img {
max-width: 100%;
max-height: 100%;
}
<div class="flex-container">
<div class="flex-item">
<img src="http://i.stack.imgur.com/mrEyQ.jpg">
</div>
</div>
【问题讨论】: