Skip to content

Instantly share code, notes, and snippets.

@davidjpfeiffer
Last active June 2, 2016 13:17
Show Gist options
  • Save davidjpfeiffer/611fb96e0fb49645336a0d61c7ddb0c5 to your computer and use it in GitHub Desktop.
Save davidjpfeiffer/611fb96e0fb49645336a0d61c7ddb0c5 to your computer and use it in GitHub Desktop.
SASS mixin to generate breakpoints for a given style
// Breakpoint Variables
$xs-break: em(400px);
$sm-break: em(600px);
$md-break: em(800px);
$lg-break: em(1000px);
$xl-break: em(1200px);
// Size Suffixes
$xs-suffix: "-xs";
$sm-suffix: "-sm";
$md-suffix: "-md";
$lg-suffix: "-lg";
$xl-suffix: "-xl";
$breakpoint-map: (
$xs-suffix: $xs-break,
$sm-suffix: $sm-break,
$md-suffix: $md-break,
$lg-suffix: $lg-break,
$xl-suffix: $xl-break
);
@mixin breakpoint($suffix, $break) {
@media (min-width: $break) {
&#{$suffix} { @content; }
}
}
@mixin breakpoints {
@each $suffix, $break in $breakpoint-map {
@include breakpoint($suffix, $break) { @content; }
}
}
.hide {
@include breakpoints {
display: none;
}
}
.show {
@include breakpoints {
display: block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment