I have a DIV which is scaled to available height using CSS flexbox. In this DIV is an image which I would like to scale along with the DIV in both dimensions. That means it should be scaled keeping its aspect ratio and the dimensions which is less than the respective DIV dimension should be centered.
I can make the image follow the width of the DIV, but not the height. Therefore, portrait images escape from the DIV bounds.
Here is a jsFiddle to demonstrate the problem.
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>