Skip to content

Instantly share code, notes, and snippets.

@rizkysyazuli
Last active February 20, 2020 14:56
Show Gist options
  • Save rizkysyazuli/b83d378a44bb97ef82d1 to your computer and use it in GitHub Desktop.
Save rizkysyazuli/b83d378a44bb97ef82d1 to your computer and use it in GitHub Desktop.
[SCSS - Breakpoints] #scss #responsive
// Here we define the lower and upper bounds for each media size
$small-range: (0em, 40em); /* 0, 640px */
$medium-range: (40.063em, 64em); /* 641px, 1024px */
$large-range: (64.063em, 90em); /* 1025px, 1440px */
$xlarge-range: (90.063em, 120em); /* 1441px, 1920px */
$xxlarge-range: (120.063em); /* 1921px */
// We use these functions to get the ranges for the media queries variables.
@function lower-bound($range){
@if length($range) <= 0 {
@return 0;
}
@return nth($range,1);
}
@function upper-bound($range) {
@if length($range) < 2 {
@return 999999999999;
}
@return nth($range, 2);
}
// Media Queries
$screen: "only screen";
$landscape: "#{$screen} and (orientation: landscape)";
$portrait: "#{$screen} and (orientation: portrait)";
$small-up: $screen;
$small-only: "#{$screen} and (max-width: #{upper-bound($small-range)})";
$medium-up: "#{$screen} and (min-width:#{lower-bound($medium-range)})";
$medium-only: "#{$screen} and (min-width:#{lower-bound($medium-range)}) and (max-width:#{upper-bound($medium-range)})";
$large-up: "#{$screen} and (min-width:#{lower-bound($large-range)})";
$large-only: "#{$screen} and (min-width:#{lower-bound($large-range)}) and (max-width:#{upper-bound($large-range)})";
$xlarge-up: "#{$screen} and (min-width:#{lower-bound($xlarge-range)})";
$xlarge-only: "#{$screen} and (min-width:#{lower-bound($xlarge-range)}) and (max-width:#{upper-bound($xlarge-range)})";
$xxlarge-up: "#{$screen} and (min-width:#{lower-bound($xxlarge-range)})";
$xxlarge-only: "#{$screen} and (min-width:#{lower-bound($xxlarge-range)}) and (max-width:#{upper-bound($xxlarge-range)})";
// Example usage
// @media #{$small-up} { }
// @media #{$small-only} { }
// @media #{$medium-up} { }
// @media #{$medium-only} { }
// @media #{$large-up} { }
// @media #{$large-only} { }
// @media #{$xlarge-up} { }
// @media #{$xlarge-only} { }
// @media #{$xxlarge-up} { }
// @media #{$xxlarge-only} { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment