When you use a percentage in height , it is calculated relative to the height of the generated block containing the block.
Since you want to calculate it in relation to the width, you can use, for example, padding-top .
To avoid affecting the contents, place them in a completely placed package.
#wrapper { padding-top: 25%; border: 1px solid; position: relative; } #content { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
<div id="wrapper"> <div id="content"> <p>Foo</p> <p>Bar</p> <p>Baz</p> </div> </div>
source share