How to make text and image columns have equal height

1 day ago 2
ARTICLE AD BOX

I have a container with a max-width and two elements side by side using flexbox:

a text block

an image

Both elements technically have the same height as flex items, but the image keeps empty space inside itself because it preserves its aspect ratio (object-contain). Visually, this makes the image column look shorter than the text column.

What I want instead is:

the image must keep its aspect ratio and must not be cropped

there should be no empty (white) space inside the image container

when the image is visually shorter because of its aspect ratio, the text container should grow horizontally (take more width) to eliminate the empty areas, instead of forcing both columns to match the height of the taller element

I tried items-stretch, but it equalizes based on the tallest element, and I actually need the layout to adapt to the shorter one.

Here is a simplified example of my layout:

<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script> <div class="max-w-6xl mx-auto flex items-stretch p-8 gap-4"> <div class="bg-[#b2c492]" style="writing-mode: vertical-rl; transform: rotate(180deg);"> <div class="p-6"> <h3 class="text-6xl">Adipisicing</h3> <p class="text-lg"> Ea nostrud duis tempor nulla id aliquip nisi quis dolor aliquip reprehenderit. </p> </div> </div> <div class="flex justify-center items-center"> <img src="https://picsum.photos/500/150" alt="Milestones" class="w-full h-auto object-contain" /> </div> </div>

I added screenshots showing:

Is this achievable with pure CSS? If yes how can I do?

Read Entire Article