It is necessary to set overflow: hidden
for container to prevent oveflowing:
.image-parent {
max-height: 50%;
overflow: hidden;
height: 100px;
}
img {
max-width: 100%;
max-height: 100%;
height: 100%;
width: 100%;
object-fit: contain
}
An example:
.image-parent {
max-height: 50%;
overflow: hidden;
height: 100px;
}
img {
max-width: 100%;
max-height: 100%;
height: 100%;
width: 100%;
object-fit: contain
}
<div class="image-parent">
<img src="http://blog.w3c.br/wp-content/uploads/2013/03/css31-213x300.png" alt="an image">
</div>