Skip to content

Instantly share code, notes, and snippets.

@mvkasatkin
Last active November 10, 2017 09:45
Show Gist options
  • Save mvkasatkin/6046ecee72902db768758bd9bae45835 to your computer and use it in GitHub Desktop.
Save mvkasatkin/6046ecee72902db768758bd9bae45835 to your computer and use it in GitHub Desktop.
CSS3 responsive aspect ratio block
<div class="ratio" style="padding-top: 40%">
<div class="ratio-content">
This block is 40% ratio height
</div>
</div>
.ratio {
/* set inline ratio padding-top in % */
position: relative;
}
.ratio-content {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment