Is there a way to maintain the aspect ratio of images within a three-column layout using CSS grid, even as the parent container width decreases below 980px?
Currently, when the parent container is reduced in size, the <img>
elements shrink but do not maintain their original height, resulting in distorted images. How can this issue be resolved?
For reference, here is an example snippet of the code:
* {box-sizing: border-box}
body {margin: 0; padding: 0; width: 100%}
.section {
position: relative;
display: flex;
margin: 0 auto;
width: 100%;
padding: 4.299rem 0;
background: red;
}
.row {
position: relative;
margin: 0 auto;
width: 80%;
max-width: 980px;
background: yellow;
}
.three-column {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: 1rem;
}
.article {position: relative;}
.image {
display: block;
width: 100%;
height: 12rem;
background: lightblue;
}
<section class="section">
<div class="row">
<div class="three-column">
<article class="article">
<img class="image" src="" alt="">
<div class="headline-wrapper top-headline-wrapper-1 headline-wrapper-mobile-padding">
<h3>THIS IS A TITLE</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Similique illum ipsam facere, veniam ullam tempore laborum.</p>
</div>
</article>
<article class="article">
<img class="image" src="" alt="">
<div class="headline-wrapper top-headline-wrapper-1 headline-wrapper-mobile-padding">
<h3>THIS IS A TITLE</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Similique illum ipsam facere, veniam ullam tempore laborum.</p>
</div>
</article>
<article class="article">
<img class="image" src="" alt="">
<div class="headline-wrapper top-headline-wrapper-1 headline-wrapper-mobile-padding">
<h3>THIS IS A TITLE</h3>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Similique illum ipsam facere, veniam ullam tempore laborum.</p>
</div>
</article>
</div>
</div>
</section>