DEV Community

loading...

Discussion on: Responsive text based on image size

Collapse
simevidas profile image
Šime Vidas

There is also .box { width: fit-content } (Autoprefixer needed). I feel this is the most simple standard way to make an element shrink-to-fit.

Collapse
afif profile image
Temani Afif Author

You probably meant width:min-content ? fit-content won't work because the largest content will define the width in this case. Even min-content won't work in all the cases. It will do only in the case of image+text where the image need to define the size (for all the other examples it won't work)

Collapse
simevidas profile image
Šime Vidas • Edited

Yes, that’s the case that I meant. Image + heading. The heading has width: 0, and the image has a specific width. We want the container to be as wide as the image, so width: fit-content.