by likeclockwork · 2y ago · 0 comments
What you have is basically just an image element with width: 100 height: auto, but it has children.
Here's an example, written with tailwind for my convenience but should be pretty legible to anyone who knows CSS:
<div class="grid place-items-center [&>*]:[grid-area:1/1]">
<img
src="https://picsum.photos/500/400?grayscale&blur=2"
class="w-full h-auto"
/>
<div>Hello.</div>
</div>
<div class="grid place-items-center [&>*]:[grid-area:1/1]">
<img
src="https://picsum.photos/500/400?grayscale&blur=2"
class="w-full h-auto"
/>
<div>Hello.</div>
</div>
<div class="grid place-items-center [&>*]:[grid-area:1/1]">
<img
src="https://picsum.photos/500/400?grayscale&blur=2"
class="w-full h-auto"
/>
<div>Hello.</div>
</div>
The height of the container is governed by the height of the image (until the text becomes taller than the image). You still have fully fleixible in terms placement (place-self) and/or sizing (height: 100%) of the text container.