Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Keep a given aspect ratio for any content
.aspectWrapper {
position: relative;
.aspectImg {
display: block;
height: auto;
position: relative;
width: 100%;
.aspectContent {
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
<div class="aspectWrapper">
<img class="aspectImg" src="5x4.blank.gif" alt />
<div class="aspectContent">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.