I needed an image to fill a div. As per this answer, the job was almost done. The problem arises when the images are somewhat larger than the div they are contained in. The images are shown at 100% scale, which in my case isn't ideal.
In Firefox the problem can be solved by using this CSS instead:
.fill img {
min-height: 100%;
}
In other browsers (tested with Chrome and Edge) this solution doesn't work and the end result is the same as before.
Is there a way to achieve the same result as in Firefox across other browsers?
Here is a fiddle with a mockup layout, demonstrating this behaviour: https://jsfiddle.net/jqe5gfru/4/
.container {
border: 2px solid red;
width: 300px;
height: 40vh;
margin: 5px;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.item {
min-height: 100%;
}
<div class="container">
<img class="item" src="http://placekitten.com/1600/400" />
</div>
<div class="container">
<img class="item" src="http://placekitten.com/600/1200" />
</div>
Try opening it in Firefox and some other browser and compare the result.