according to this Q/A I always used padding-top
or padding-bottom
to maintan the aspect ratio of a div. Today I faced simple structure which is not rendered with aspect of 5/2 (w/h). For padding-top:40%
I expect a horizontal rectangle as the padding-top
is calculated against the width. Why this is vertical? (It seems that the height is calculated against the parent width)
#aspect52 {
width:30%;
padding-top:40%;
background:#ff0000;
position:absolute;
}
#parent{
position:relative;
width:100%;
}
<div id="parent">
<div id="aspect52"></div>
</div>