That's because
h1
have some vertical margin by default, usually 0.67em
.
- The top margin of
h1
collapses
height
never includes the height of the margin area
Since the top margin of h1
collapses, it behaves like the margin belonged to the header
instead of the h1
. Since the content height of the h1
is 10%
, its total height will be calc(10% + 0.67em)
.
That's why there is overflow.
If you remove the top margin but leave the bottom one there is no problem, because the bottom one does not collapse, due to the non-auto
height
. From Collapsing margins,
Two margins are adjoining if [...] both belong to vertically-adjacent
box edges, [... e.g.]
- top margin of a box and top margin of its first in-flow child
- bottom margin of a last in-flow child and bottom
margin of its parent if the parent has
auto
computed height.
So you can do any of the following
- Remove
h1
's top margin
- Prevent the margin collapse
- Propose a
box-sizing: margin-box
to the CSS Working Group. It will probably be rejected.