Skip to content

Instantly share code, notes, and snippets.

@andregoncalves
Last active November 18, 2017 11:57
Show Gist options
  • Save andregoncalves/f37d0dc34b045a07e1f2f526fe538af7 to your computer and use it in GitHub Desktop.
Save andregoncalves/f37d0dc34b045a07e1f2f526fe538af7 to your computer and use it in GitHub Desktop.
CSS maintain block aspect ratio
<style>
.aspect-ratio {
padding-top: calc(1 / (16 / 9) * 100%);
position : relative;
}
.aspect-wrapper {
position: absolute;
top:0;
left:0;
width:100%;
height:100%;
}
</style>
<div class="aspect-ratio">
<div class="aspect-wrapper">
Maintains block aspect ratio at different resolutions
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment