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)
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.You probably meant
width:min-content
?fit-content
won't work because the largest content will define the width in this case. Evenmin-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)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, sowidth: fit-content
.