Percentage height needs a definite containing block
.outer { height: 8rem; }
.inner { height: 100%; }
.auto { height: auto; }
.auto .inner { height: 100%; }height: 100% can fill an 8rem parent. The same 100% inside a height: auto parent does not have a definite containing-block height to resolve against.
- This is a specified-value rule, not a measured pixel height from a browser. Flex and Grid stretching are not used here so the percentage rule stays visible.
<div class="outer">
<div class="inner">100% of an 8rem parent</div>
</div>
<div class="auto">
<div class="inner">100% of an auto-height parent</div>
</div>
<style>
.outer, .auto { width: 16rem; font-family: sans-serif; border: 1px solid #0B5853; }
.outer { height: 8rem; }
.auto { height: auto; }
.inner { height: 100%; background: #F3EFE4; }
</style>What this markup means
The first inner box is 100% of a parent with a definite 8rem height, so the percentage can resolve. The second parent has height: auto, so the child’s height: 100% has no definite containing-block height and is treated as auto, shrinking to the content rather than stretching the auto parent. This example does not set display: flex or grid, which have their own stretching rules on the Flexbox and Grid pages.