Add mixin for HiDPI CSS images

This commit is contained in:
Justin Edmund 2023-01-22 14:39:28 -08:00
parent 4287c3008f
commit 6fd95d3168

View file

@ -26,3 +26,36 @@
}
}
}
@mixin hidpiImage(
$image,
$extension,
$width,
$height,
$position: center,
$repeat: no-repeat
) {
background: url($image + '.' + $extension) $repeat $position;
@media screen and (-webkit-min-device-pixel-ratio: 2),
screen and (min--moz-device-pixel-ratio: 2),
screen and (-moz-min-device-pixel-ratio: 2),
screen and (-o-min-device-pixel-ratio: 2/1),
screen and (min-device-pixel-ratio: 2),
screen and (min-resolution: 192dpi),
screen and (min-resolution: 2dppx) {
background: url($image + '@2x' + '.' + $extension) $repeat $position;
background-size: $width $height;
}
@media screen and (-webkit-min-device-pixel-ratio: 3),
screen and (min--moz-device-pixel-ratio: 3),
screen and (-moz-min-device-pixel-ratio: 3),
screen and (-o-min-device-pixel-ratio: 3/1),
screen and (min-device-pixel-ratio: 3),
screen and (min-resolution: 216dpi),
screen and (min-resolution: 3dppx) {
background: url($image + '@3x' + '.' + $extension) $repeat $position;
background-size: $width $height;
}
}