Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Last active December 29, 2016 17:06
Show Gist options
  • Save VitorLuizC/fd1ff44b0f3f27bcad97ab61417b6dca to your computer and use it in GitHub Desktop.
Save VitorLuizC/fd1ff44b0f3f27bcad97ab61417b6dca to your computer and use it in GitHub Desktop.
CSS Breakpoints mixin for SASS + example usage
$_BREAKPOINTS: (
print: print,
xs: screen, // mobile-first fallback
sm: 48rem,
md: 64rem,
lg: 75rem
) !global;
@mixin breakpoint($point, $type: min) {
@if (type-of($point) == string) {
$point: map-get($_BREAKPOINTS, $point);
@if ($point == null) {
@error 'invalid breakpoint "#{$point}".';
}
}
$query: if(type-of($point) == number, '(#{$type}-width: #{$point})', $point);
@media #{$query} {
@content;
}
}
// Usage
// @include breakpoint(md) {
// height: 3.125rem;
// }
// @include breakpoint(48.625rem, max) { // Custom breakpoint
// height: calc(2rem + 2px);
// border-width: 2px 0;
// }
// @include breakpoint(print) {
// border-radius: unset;
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment