Created
November 21, 2012 02:11
-
-
Save jakejscott/4122625 to your computer and use it in GitHub Desktop.
Fluid Ratio images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// credit Rolf Timmermans | |
// http://voormedia.com/blog/2012/11/responsive-background-images-with-fixed-or-fluid-aspect-ratios | |
/* Calculate fluid ratio based on two dimensions (width/height) */ | |
@mixin fluid-ratio($large-size, $small-size) { | |
$width-large: nth($large-size, 1); | |
$width-small: nth($small-size, 1); | |
$height-large: nth($large-size, 2); | |
$height-small: nth($small-size, 2); | |
$slope: ($height-large - $height-small) / ($width-large - $width-small); | |
$height: $height-small - $width-small * $slope; | |
padding-top: $slope * 100%; | |
height: $height; | |
background-size: cover; | |
-moz-background-size: cover; /* Firefox 3.6 */ | |
background-position: center; /* Internet Explorer 7/8 */ | |
} | |
figure.fluidratio { | |
/* This element will have fluid ratio from 4:1 at 800px to 2:1 at 300px. */ | |
@include fluid-ratio(800px 200px, 300px 150px); | |
background-image: url(http://voormedia.com/examples/amsterdam.jpg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment