Skip to content

Instantly share code, notes, and snippets.

@kogakure
Created September 17, 2013 14:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kogakure/6595093 to your computer and use it in GitHub Desktop.
Save kogakure/6595093 to your computer and use it in GitHub Desktop.
HTML/CSS: Intrinsic Ratios image solution for responsive images
<div class="img-container">
<img src="http://cdn3.spiegel.de/images/image-545702-breitwandaufmacher-penw.jpg">
</div>
.img-container {
background: red;
position: relative;
height: 0;
padding-bottom: 37.209302326%; /* 43:16 ratio */
overflow: hidden;
}
.img-container img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment