Problem with using percentage as a unit with respect to the min-height property
Hello guys, sorry to disturb you all; can someone explain why my box1 isn't appearing, it's like it doesn't have any height because when I change the height from a percentage to another unit, it works well, but not here
3 Replies
This is one of those quirks of CSS where you need to have an explicit height on the parent for the percentage to be used. you have a
min-height
on your body, which for the purpose of "parent container's height" is auto
. To avoid infinite loops where the height of the parent is based on the content of the children and the height of the children are based on the height of the parent…CSS just assumes any non-set height to be 0
for the purpse of children with percentage-based heights.
What you can do is give .box1
an explicit height based on what you know the parent will be. The parent is min-height: 100vh;
, so we can set .box1
's height to 50vh
. It's the same thing but you're using explicit numbers instead of percentages and CSS doesn't care.https://discord.com/channels/436251713830125568/1215661399594766448/1215667555671220294
https://youtu.be/6aHKdahOfCc?si=u-K_QRW72b900SB0
Check out both these videos from KPow
ty !