Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created October 11, 2011 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/1278476 to your computer and use it in GitHub Desktop.
Save barneycarroll/1278476 to your computer and use it in GitHub Desktop.
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