I am struggling to create a grid layout for posts where the images maintain the same dimensions regardless of their size. I just can't seem to crack it. For example, whether it's a square image or a rectangle image, they should appear in the same dimension.
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.blog-container {
width: 90%;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 1rem;
margin: 0 auto;
}
img {
max-width: 100%;
height: 100%;
object-fit: cover;
display: block;
}
<div class="blog-container">
<div class="post">
<div class="img">
<img src="pic1.jpg" alt="">
</div>
<div class="content">
<h2>Post title 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sagittis ex eu dolor auctor, bibendum luctus turpis feugiat.
Maecenas porttitor felis purus. Maecenas neque libero, tristique in mattis ac, suscipit non turpis.</p>
</div>
</div>
<div class="post">
<div class="img">
<img src="pic2.jpg" alt="">
</div>
<div class="content">
<h2>Post title 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sagittis ex eu dolor auctor, bibendum luctus turpis feugiat.
Maecenas porttitor felis purus. Maecenas neque libero, tristique in mattis ac, suscipit non turpis.</p>
</div>
</div>
<div class="post">
<div class="img">
<img src="pic1.jpg" alt="">
</div>
<div class="content">
<h2>Post title 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sagittis ex eu dolor auctor, bibendum luctus turpis feugiat.
Maecenas porttitor felis purus. Maecenas neque libero, tristique in mattis ac, suscipit non turpis.</p>
</div>
</div>
<div class="post">
<div class="img">
<img src="pic2.jpg" alt="">
</div>
<div class="content">
<h2>Post title 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sagittis ex eu dolor auctor, bibendum luctus turpis feugiat.
Maecenas porttitor felis purus. Maecenas neque libero, tristique in mattis ac, suscipit non turpis.</p>
</div>
</div>
</div>
But this is what I currently have https://i.sstatic.net/wr09j.jpg