Created
November 12, 2013 16:00
-
-
Save richardvenneman/7433385 to your computer and use it in GitHub Desktop.
This bg-variants mixin is a responsive images solution which supports multiple screen widths and densities. It uses CSS3 multiple backgrounds and is an improvement in user experience over just specifying backgrounds since any low res background image specified later in the stack will load first. This solution doesn't play well with IE8 as it wil…
This file contains hidden or 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
//----------------------------------------------------------------------------- | |
// Background Variants | |
@mixin bg-variants($filename, $path: '/online/', $extension: 'jpg') { | |
background-image: url(#{$path + $filename + '.small.' + $extension}); | |
@include hidpi(1.5) { | |
background-image: | |
url(#{$path + $filename + '.small@2x.' + $extension}), | |
url(#{$path + $filename + '.small.' + $extension}); | |
} | |
@include respond-to($break-2) { | |
background-image: | |
url(#{$path + $filename + '.medium.' + $extension}), | |
url(#{$path + $filename + '.small.' + $extension}); | |
@include hidpi(1.5) { | |
background-image: | |
url(#{$path + $filename + '.medium@2x.' + $extension}), | |
url(#{$path + $filename + '.small.' + $extension}); | |
} | |
} | |
@include respond-to($break-3) { | |
background-image: | |
url(#{$path + $filename + '.large.' + $extension}), | |
url(#{$path + $filename + '.small.' + $extension}); | |
@include hidpi(1.5) { | |
background-image: | |
url(#{$path + $filename + '.large@2x.' + $extension}), | |
url(#{$path + $filename + '.small@2x.' + $extension}); | |
} | |
} | |
@include respond-to($break-4) { | |
background-image: | |
url(#{$path + $filename + '.huge.' + $extension}), | |
url(#{$path + $filename + '.small' + $extension}); | |
@include hidpi(1.5) { | |
background-image: | |
url(#{$path + $filename + '.huge@2x.' + $extension}), | |
url(#{$path + $filename + '.small@2x.' + $extension}); | |
} | |
} | |
} |
This file contains hidden or 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
//----------------------------------------------------------------------------- | |
// Respond To | |
@mixin respond-to($breakpoint) { | |
@media only screen and (min-width: $breakpoint) { @content; } | |
} |
This file contains hidden or 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
//----------------------------------------------------------------------------- | |
// Settings | |
$break-1: 480px; | |
$break-2: 768px; | |
$break-3: 1024px; | |
$break-4: 1440px; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment