Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Keep a given aspect ratio for any content
<style>
.aspectWrapper {
position: relative;
}
.aspectImg {
display: block;
height: auto;
position: relative;
width: 100%;
}
.aspectContent {
height: 100%;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
</style>
<div class="aspectWrapper">
<img class="aspectImg" src="5x4.blank.gif" alt />
<div class="aspectContent">
whatever
</div>
</dib>
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.