The title says most of it. My html:
<div class="wrap">
<div class="s-inner">
<figure>
<img>
</figure>
</div>
</div>
CSS:
.wrap{
max-width:500px;
max-height:200px;
background:red;
}
.s-inner{
position: relative;
margin: inherit;
padding:inherit;
display: -webkit-flex;
display: flex;
max-height: 100%;
max-width: 100%;
box-sizing:inherit;
margin:auto;
}
/* Inside */
.s-inner > figure{
display: block;
margin: 0 auto 0 auto;
box-sizing: border-box;
}
.s-inner > figure > img{
box-sizing: border-box;
max-width: 100%;
max-height: 100%;
}
If you inspect the .wrap div you will notice that the image is popping out and being larger than the div,how that be fixed for image to scale the .wrap div size.Fiddle