In my design, I have two sets of images displayed below:
https://i.sstatic.net/pQytw.jpg
Both sets of images have the exact same code. The only difference between the images in the first and second set is their dimensions.
I aim to make all image blocks appear the same height and width, regardless of the image dimensions. I also want the image width to be 100% of the available width, with the height set to auto. If the image's height exceeds its parent's height, I want the excess part of the image to be hidden.
Below is the HTML code snippet:
<div class="container-fluid">
<div class="row top-row">
<div class="col-md-2">
<div class="col-md-12 menu-top-wrapper">
<img src="https://lorempixel.com/900/500?r=1" class="menu-top-img" />
</div>
<div class="col-md-6 menu-left-wrapper">
<img src="https://lorempixel.com/900/500?r=2" class="menu-left-img" />
</div>
<div class="col-md-6 menu-right-wrapper">
<img src="https://lorempixel.com/900/500?r=3" class="menu-right-img" />
</div>
</div>
<div class="col-md-2">
<div class="col-md-12 menu-top-wrapper">
<img src="https://lorempixel.com/500/900?r=1" class="menu-top-img" />
</div>
<div class="col-md-6 menu-left-wrapper">
<img src="https://lorempixel.com/500/900?r=2" class="menu-left-img" />
</div>
<div class="col-md-6 menu-right-wrapper">
<img src="https://lorempixel.com/500/900?r=3" class="menu-right-img" />
</div>
</div>
</div>
</div>
Take a look at the CSS styling:
.menu-left-wrapper {
margin-top: 2px;
padding-right: 2px;
}
.menu-right-wrapper {
margin-top: 2px;
padding-left: 2px;
}
.menu-top-img {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.menu-left-img {
border-bottom-left-radius: 10px;
}
.menu-right-img {
border-bottom-right-radius: 10px;
}
.img-top-wrapper,
.img-left-wrapper,
.img-right-wrapper {
position: relative;
width: auto;
height: 100px;
overflow: hidden;
}
.menu-top-img,
.menu-left-img,
.menu-right-img {
position: relative;
width: 100%;
height: auto;
}
For a live example, see the JS Fiddle link below: