I'm currently working on a website section where I want to display text next to an image. However, the image is not behaving as expected and is stretching out its parent div instead of taking up 100% of the specified height.
According to my understanding, the height I set in the .more-info-section should be passed down to the child div .info-image-container, and then to the image itself. But when I insert the image, it stretches the parent .info-image-container while the height of .more-info-section remains fixed at 30rem.
.more-info-section {
height: 30rem;
display: grid;
grid-template-columns: 1fr 1fr;
}
.info-image-container {
height: 100%;
width: 100%;
}
.info-image {
height: 100%;
width: 100%;
object-fit: cover;
}
.info-info {
overflow: auto;
}
<div class="more-info-section">
<div class="info-image-container">
<img class="info-image" src="Images/bag2.jpg">
</div>
<div class="info-info">
<h1>The Header</h1>
<p>text</p>
</div>
</div>
If I explicitly add height: 30rem
to .info-image-container, the image scales down but doesn't crop properly due to the object-fit:cover
. It's clear that I'm missing something here, but I just can't seem to figure out what it is.