Skip to content

Instantly share code, notes, and snippets.

@ktusznio
Created July 28, 2017 16:44
Show Gist options
  • Save ktusznio/cb0b80bf6c08d328cd5ec43e41cd03d5 to your computer and use it in GitHub Desktop.
Save ktusznio/cb0b80bf6c08d328cd5ec43e41cd03d5 to your computer and use it in GitHub Desktop.
Responsive SASS mixins for retina displays
.hero {
background: url('/images/hero-mobile.jpg') no-repeat center center;
background-size: cover;
@include breakpoint(tablet) {
background-image: url('/images/hero.jpg');
}
@include retina {
background-image: url('/images/[email protected]');
@include breakpoint(tablet) {
background-image: url('/images/[email protected]');
}
}
}
@mixin breakpoint($media) {
@if $media == tablet {
@media only screen and (min-width: $screen-md-min) { @content; }
} @else if $media == desktop {
@media only screen and (min-width: $screen-lg-min) { @content; }
}
}
@mixin retina {
@media only screen and (min--moz-device-pixel-ratio: 2),
only screen and (-o-min-device-pixel-ratio: 2/1),
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min-device-pixel-ratio: 2) {
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment