我有一个DIV,使用CSS flexbox将其缩放到可用高度。在这个DIV中有一张图像,我希望它与DIV一起按比例缩放,较小的维度应居中。我可以使图像遵循DIV的宽度,但不能遵循高度,因此纵向图像会超出DIV的范围。这里是一个jsFiddle演示问题: https://jsfiddle.net/aer69rcr/
html, body {
height: 100%;
margin: 0;
}
.container {
display: flex;
flex-direction: column;
height: 100%;
}
.box {
flex: 1 1 auto;
display: flex;
justify-content: center;
align-items: center;
}
.box img {
width: auto;
height: auto;
max-width: 90%;
max-height: 90%;
}
<div class="container">
<div class="box"></div>
<div class="box" style="background: pink;">
<img src="//dummyimage.com/300" />
</div>
<div class="box"></div>
</div>