When manually specifying a height for images, they will try to occupy that specified height. However, if the images are roughly square and have a `width` attribute set to `100%`, they will only expand in height until they reach the maximum width. This results in gaps between the images.
If you are aiming to achieve a specific layout by setting a fixed height for the images, keep in mind that you cannot specify both a height and restrict the width without creating gaps. Removing the fixed height from the `.image` class is a solution to this issue:
body {
max-width: 500px; /* Showcasing the problem */
}
.image {
width: 100%;
/*height: 560px;*/ /* Commented out to avoid gaps */
overflow: hidden;
display: flex;
align-items: center;
margin: 0 auto 0;
border: 1px solid blue; /* Added to show the separation between images */
}
.image>img {
width: 100%;
height: auto;
}
<div class="image">
<img src="http://placehold.it/100" />
</div>
<div class="image">
<img src="http://placehold.it/100" />
</div>
I hope this explanation is helpful! :)