I have three types of images with different height and width.
Now what I am doing is, I have to display all with equal height and width.
Note: I don't want to use a background image. I am getting images form database
Snippet 1
I tried box
with height
and width:300px
and img height:auto
but images are not displaying with equal.
ul li {
display: inline-block;
}
.box {
width: 300px;
height: 300px;
border: 1px solid #000;
}
.box img {
width: 100%;
height: auto;
}
<ul>
<li>
<div class="box">
<img src="https://cdn2.expertreviews.co.uk/sites/expertreviews/files/styles/er_main_wide/public/2019/03/best-external-hard-drive-sandisk_extreme_ssd.jpg?itok=aIFHiCLL">
</div>
</li>
<li>
<div class="box">
<img src="https://images.unsplash.com/photo-1576973630537-dd588987df10?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80">
</div>
</li>
<li>
<div class="box">
<img src="https://images-na.ssl-images-amazon.com/images/I/712xVgJWSbL._SX466_.jpg">
</div>
</li>
</ul>
Snippet 2
I tried with height: 100%; object-fit: cover;
to the img tag but in this images are displaying big in the box.
ul li {
display: inline-block;
}
.box {
width: 300px;
height: 300px;
border: 1px solid #000;
}
.box img {
width: 100%;
height: 100%;
object-fit: cover;
}
<ul>
<li>
<div class="box">
<img src="https://cdn2.expertreviews.co.uk/sites/expertreviews/files/styles/er_main_wide/public/2019/03/best-external-hard-drive-sandisk_extreme_ssd.jpg?itok=aIFHiCLL">
</div>
</li>
<li>
<div class="box">
<img src="https://images.unsplash.com/photo-1576973630537-dd588987df10?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80">
</div>
</li>
<li>
<div class="box">
<img src="https://images-na.ssl-images-amazon.com/images/I/712xVgJWSbL._SX466_.jpg">
</div>
</li>
</ul>
Would you help me out?