I'm looking to stack an image on top of text inside a fixed height div. The challenge is to make the image's size based on the amount of space left after accommodating the text within the same area. Ideally, I would like to achieve this using only CSS without involving JavaScript.
Here are more specific details regarding the requirement:
If the text spans three lines, then the image should have a max-width: 100%
and a maximum height that does not exceed the remaining space in the div after accounting for the height of the text. For example, if the parent div has a height of 750px and the text requires 100px of space, the image should be allowed to be at most 650px tall.
I've attempted to use flexbox properties like flex-column
but struggled to confine the size of the image accordingly. When I tried stacking two divs where the top one was scaling with the text but encountered issues when adding the image.
My question is whether achieving this layout is feasible using only CSS.
To illustrate what I currently have and the functionality issue, you can view the example here: https://jsfiddle.net/aoqerm06/
<div style="height: 400px;" class="d-flex flex-column">
<div class="bg-primary h-100" >
IMAGE GOES HERE
</div>
<div class="flex-grow-1">
LOTS OF TEXT HERE
</div>
</div>