Skip to content

Instantly share code, notes, and snippets.

@KATT
Last active December 26, 2015 22:59
Show Gist options
  • Save KATT/7227004 to your computer and use it in GitHub Desktop.
Save KATT/7227004 to your computer and use it in GitHub Desktop.
// declare in your variables-file
$relative-image-path = '../images/';
$retina = '(-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)';
responsive-image($image) {
$path = $relative-image-path + $image;
$ext = extname($path);
$path2x = pathjoin(dirname($path), basename($path, $ext) + '@2x' + $ext);
box-sizing: content-box;
max-width: 100%;
$size = image-size($path);
padding-top: unit(($size[1] / $size[0])*100, '%');
background-image: url($path);
background-repeat: no-repeat;
background-size: contain;
@media $retina {
background-image: url($path2x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment