Skip to content

Instantly share code, notes, and snippets.

@Razenbull
Created August 31, 2015 10:06
Show Gist options
  • Save Razenbull/217fa13815eab97507cd to your computer and use it in GitHub Desktop.
Save Razenbull/217fa13815eab97507cd to your computer and use it in GitHub Desktop.
helper mixin to display responsive images
// helper mixin to display retina images
//
// @param {List *required} nth($display, 1) - display
// @param {List *optional} nth($display, 2) - width
//
// image-1x is display and hide on high resolution screens
// image-2x is hide and display on high resolution screens
//
// @use @include image-retina(inline, 60px);
@mixin image-retina($display...) {
> .image-1x {
display: nth($display, 1);
@include hdpi(2) {
display: none;
}
}
> .image-2x {
display: none;
@include hdpi(2) {
display: nth($display, 1);
}
}
@if length($display) > 1 {
> .image-1x,
> .image-2x {
width: nth($display, 2);
}
}
}
<a class="retina" href="#">
<img class="image-1x" alt="youtic" src="/images/logoyoutic.png">
<img class="image-2x" alt="youtic" src="/images/logoyoutic@2x.png">
</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment