Skip to content

Instantly share code, notes, and snippets.

@mgerring
Last active December 17, 2015 21:19
Show Gist options
  • Save mgerring/5674279 to your computer and use it in GitHub Desktop.
Save mgerring/5674279 to your computer and use it in GitHub Desktop.
Responsive placeholders in SASS
@mixin media-breakpoint($point) {
// &{ @content; } doesn't mean anything in the compiled output,
// but will workaround a SASS compiler issue that doesn't let
// us use %placeholders inside nested media queries.
@if $point == 'tablet-up' {
@media screen and (min-width: 48em) { &{ @content; } }
}
@else if $point == 'desktop-up' {
@media screen and (min-width: 60em) { &{ @content; } }
}
@else if $point == 'widescreen-up' {
@media screen and (min-width: 71.25em) { &{ @content; } }
}
@else if $point == 'desktop-down' {
@media screen and (max-width: 71.249) { &{ @content; } }
}
@else if $point == 'tablet-down' {
@media screen and (max-width: 59.999em) { &{ @content; } }
}
@else if $point == 'phone-down' {
@media screen and (max-width: 47.999em) { &{ @content; } }
}
}
@mixin responsive-placeholder($name) {
%#{$name} {
@content;
}
%#{$name}-response {
@include media-breakpoint ('tablet-up') { @content; }
@include media-breakpoint ('desktop-up') { @content; }
@include media-breakpoint ('widescreen-up') { @content; }
@include media-breakpoint ('desktop-down') { @content; }
@include media-breakpoint ('tablet-down') { @content; }
@include media-breakpoint ('phone-down') { @content; }
}
}
@mgerring
Copy link
Author

Also, I'd really rather do this in LESS, but SCSS is the only preprocessor with the requisite features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment