How can I make all images of different height and width the same via CSS?

ariel picture ariel · Oct 17, 2013 · Viewed 306.2k times · Source

I am trying to create an image wall consisting of product photos. Unfortunately, all of them are of different height and width. How can I use css to make all images look the same size? preferably 100 x 100.

I was thinking of doing a div that has height and width of 100px and then some how filling it up. NOt sure how to do that.

How can I accomplish this?

Answer

Simon Arnold picture Simon Arnold · Oct 17, 2013

Updated answer (No IE11 support)

img {
    float: left;
    width:  100px;
    height: 100px;
    object-fit: cover;
}
<img src="http://i.imgur.com/tI5jq2c.jpg">
<img src="http://i.imgur.com/37w80TG.jpg">
<img src="http://i.imgur.com/B1MCOtx.jpg">

Original answer

.img {
    float: left;
    width:  100px;
    height: 100px;
    background-size: cover;
}
<div class="img" style="background-image:url('http://i.imgur.com/tI5jq2c.jpg');"></div>
<div class="img" style="background-image:url('http://i.imgur.com/37w80TG.jpg');"></div>
<div class="img" style="background-image:url('http://i.imgur.com/B1MCOtx.jpg');"></div>