I'm learning CSS Grid and I have a problem with image resizing.
To show you the problem, I created a main layout with 2 columns and inside the first column, I created another grid where I wanted to place an image and some text in a column.
Please delete the html comment, so that you'll see the image.
In the code snippet, the red area shows the cell where the image should go. Now, the image is larger than the red 'container' (height: 200px) grid-cell and I want the image to shrink inside the cell, so that it fits inside and keeps the aspect ratio (cut-offs left/right or top/bottom are needed). Object-fit on the image doesn't work. Positioning the image like "object-position: 50% 50%" would also be nice but that doesn't work either. I'm currently not sure how to fix this problem.
.mainlayout {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: auto;
}
.media {
grid-column: 1 / 2;
grid-row: 1;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 200px auto auto;
}
.media .image {
grid-column: 1;
grid-row: 1;
background-color: red;
}
.media h4 {
grid-column: 1;
grid-row: 2;
}
.media p {
grid-column: 1;
grid-row: 3;
}
<section class="mainlayout">
<div class="media">
<div class="image">
<!--<img src="http://placehold.it/1000x1000">-->
</div>
<h4>Card title</h4>
<p>Some quick example text to build on the card title and make up the bulk of the card's content.</p>
</div>
</section>
Thank you for your help.