Last active
July 27, 2022 14:42
-
-
Save humayunahmed8/3f34a647828bcb1d2209b203b79b2285 to your computer and use it in GitHub Desktop.
Sass Advance Responsive Mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Breakpoints. | |
$breakpoints: ( | |
xs: 425px, | |
sm: 576px, | |
md: 768px, | |
lg: 992px, | |
xl: 1200px, | |
xxl: 1400px, | |
c1600: 1600px, | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Respond above. | |
@mixin respond-above($breakpoint) { | |
// If the breakpoint exists in the map. | |
@if map-has-key($breakpoints, $breakpoint) { | |
// Get the breakpoint value. | |
$breakpoint-value: map-get($breakpoints, $breakpoint); | |
// Write the media query. | |
@media (min-width: $breakpoint-value) { | |
@content; | |
} | |
// If the breakpoint doesn't exist in the map. | |
} @else { | |
// Log a warning. | |
@warn 'Invalid breakpoint: #{$breakpoint}.'; | |
} | |
} | |
// Respond Below | |
@mixin respond-below($breakpoint) { | |
// If the breakpoint exists in the map. | |
@if map-has-key($breakpoints, $breakpoint) { | |
// Get the breakpoint value. | |
$breakpoint-value: map-get($breakpoints, $breakpoint); | |
// Write the media query. | |
@media (max-width: ($breakpoint-value - 1)) { | |
@content; | |
} | |
// If the breakpoint doesn't exist in the map. | |
} @else { | |
// Log a warning. | |
@warn 'Invalid breakpoint: #{$breakpoint}.'; | |
} | |
} | |
// Respond Between | |
@mixin respond-between($lower, $upper) { | |
// If both the lower and upper breakpoints exist in the map. | |
@if map-has-key($breakpoints, $lower) and map-has-key($breakpoints, $upper) | |
{ | |
// Get the lower and upper breakpoints. | |
$lower-breakpoint: map-get($breakpoints, $lower); | |
$upper-breakpoint: map-get($breakpoints, $upper); | |
// Write the media query. | |
@media (min-width: $lower-breakpoint) and (max-width: ($upper-breakpoint - 1)) { | |
@content; | |
} | |
// If one or both of the breakpoints don't exist. | |
} @else { | |
// If lower breakpoint is invalid. | |
@if (map-has-key($breakpoints, $lower) ==false) { | |
// Log a warning. | |
@warn 'Your lower breakpoint was invalid: #{$lower}.'; | |
} | |
// If upper breakpoint is invalid. | |
@if (map-has-key($breakpoints, $upper) ==false) { | |
// Log a warning. | |
@warn 'Your upper breakpoint was invalid: #{$upper}.'; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (max-width: 1599px) | |
@include respond-below(c1600) { | |
} | |
// (max-width: 1399px) | |
@include respond-below(xxl) { | |
} | |
// (max-width: 1199px) | |
@include respond-below(xl) { | |
} | |
// (min-width: 992px) and (max-width: 1199px) | |
@include respond-between(lg, xl) { | |
} | |
// (max-width: 991px) | |
@include respond-below(lg) { | |
} | |
// (max-width: 767px) | |
@include respond-below(md) { | |
} | |
// (max-width: 575px) | |
@include respond-below(sm) { | |
} | |
// (max-width: 424px) | |
@include respond-below(xs) { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment