<div class="h-fit w-fit min-h-fit min-w-fit resize overflow-hidden bg-gray-200">
<div> Content goes here.</div>
<div> Content goes here.</div>
<div> Content goes here.</div>
<div> Content goes here.</div>
<div> Content goes here.</div>
</div>
The above is a minimal example tested in firefox
and edge
.
Even though it uses tailwind i have tried with inline styles too.
min-w-fit
(min-width: fit-content) works as expected but the equivalent for min height does not.
3
Answers
The problem arises because min-height: fit-content calculates the minimum height based on the content inside the element. However, when combined with the resize property, which allows users to resize elements dynamically, browsers struggle to accurately calculate and adjust the height in real-time.
Example of JavaScript Approach:
In order for that to work you need to set a static value like min-h-[200px], but you don’t wanna do that, so a workaround would be:
Remove
min-h-fit
and after the element renders, get it’s height using JS and set it as a static minimum heightThe min-height: fit-content property in CSS is intended to make an element’s minimum height just enough to fit its content. However, it may not work as expected when combined with certain other properties, such as resizing. If you encounter issues with min-height: fit-content when resizing an element.