I am facing an issue with aligning an image to the bottom of a parent container that has child elements, such as paragraphs with varying heights based on content. I attempted to use justify-self: flex-end
to align the image vertically at the bottom without affecting other items in the parent container but it did not work.
When I tried using justify-content: flex-end
, the entire content shifted to the bottom, whereas I only want the image to be aligned at the bottom. What could be the mistake in my approach and how can this be fixed?
.parent-container {
display: flex;
}
.parent-container > div {
display: flex;
flex-direction: column;
flex-wrap: wrap;
margin: 0 10px;
/*justify-content: flex-end;*/
flex: 1;
}
.img-container {
justify-self: flex-end;
}
.img-container img {
width: 100%;
justify-self: flex-end;
}
<div class="parent-container">
<div>
<h3>header 1</h3>
<p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</p>
<div class="img-container">
<img src="https://place-hold.it/300x500">
</div>
</div>
<div>
<h3>header 2</h3>
<p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</p>
<div class="img-container">
<img src="https://place-hold.it/300x500">
</div>
</div>
<div>
<h3>header 3</h3>
<p>Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.</p>
<div class="img-container">
<img src="https://place-hold.it/300x500">
</div>
</div>
</div>