Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Last active December 23, 2015 15:19
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 craigmdennis/6655047 to your computer and use it in GitHub Desktop.
Save craigmdennis/6655047 to your computer and use it in GitHub Desktop.
A LESS mixin to create fluid images with no re-flow, based on intrinsic ratios and absolute positioning. Reference: http://mobile.smashingmagazine.com/2013/09/16/responsive-images-performance-problem-case-study http://alistapart.com/article/creating-intrinsic-ratios-for-video
.responsive-img(@width, @height) {
@ratio: (@height / @width) * 100;
position: relative;
padding-bottom: ~"@{ratio}%";
height: 0;
img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
}
.img-container {
.responsive-img(400,300);
}
<div class="img-container">
<img src="http://placehold.it/400x300">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment