This is untrue. This minor gimmick only happens when you try to using percentage-based top/bottom margins and /or paddings. Height is computed as percentage of the containing parent's own calculated height - see example here: http://jsfiddle.net/teddyrised/gB65X/
Let's say we have the markup:
<div>
<img src="http://placehold.it/500x500" />
</div>
and the following CSS:
body {
height: 500px;
}
div {
overflow: hidden;
height: 75%;
}
div img {
display: block;
}
<div>
will, by default behavior, stretch to the full height of parent (100% = 500px). But since we restrict it's height to 75%, it will have a final computed height of 375px.
Now you set the padding of the <div>
to 10%: http://jsfiddle.net/teddyrised/gB65X/1/
You can see that the padding, curiously, are equal along both axis, which should not be the case. If you check your inspector, you can see that the computed padding of top/bottom is identical to that of left/right, even though the height and the width of the wrapping parent, <body>
, are not the same.
In fact, this behavior is commonly exploited to create perfectly squared CSS elements without the use of JS: http://jsfiddle.net/teddyrised/gB65X/2/ If we make the following modifications to the original fiddle:
div {
overflow: hidden;
padding-bottom: 50%;
height: 0;
width: 50%;
}
You can see that <div>
has effectively become a flexible/responsible square whose dimensions depends solely on the viewport width, not height ;)