Skip to content

Instantly share code, notes, and snippets.

@arharp
Last active June 24, 2016 01:57
Show Gist options
  • Save arharp/bb7516a46cce8e997a09b6a3f9263a3a to your computer and use it in GitHub Desktop.
Save arharp/bb7516a46cce8e997a09b6a3f9263a3a to your computer and use it in GitHub Desktop.
Sass Media Query Mixin using Bootstrap Responsive Breakpoints
// Usage:
//
// @include media-query(xs) {
// // CSS for XS devices
// }
//
// @include media-query(sm, lg) {
// // CSS for small through large devices
// }
@mixin media-query($min, $max: false) {
@if $max == false { $max: $min; }
$breakpoints-min: (
xs: false,
sm: $screen-sm-min,
md: $screen-md-min,
lg: $screen-lg-min
);
$breakpoints-max: (
xs: $screen-xs-max,
sm: $screen-sm-max,
md: $screen-md-max,
lg: false
);
$expr: 'only screen ';
$min-px: map-get($breakpoints-min, $min);
@if $min-px != false {
$expr: "#{$expr} and (min-width: #{$min-px})";
}
$max-px: map-get($breakpoints-max, $max);
@if $max-px != false {
$expr: "#{$expr} and (max-width: #{$max-px})";
}
@media #{$expr} {
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment