Created
March 12, 2019 08:06
-
-
Save mikem33/cd17d9a7f129b8b8df009f23f75e6bd8 to your computer and use it in GitHub Desktop.
Media Queries Sass Mixins
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
// $Media $Queries | |
@mixin above($value, $width: true) { | |
@if $width { | |
@media (min-width: em($value)) { | |
@content; | |
} | |
} @else { | |
@media (min-height: em($value)) { | |
@content; | |
} | |
} | |
} | |
@mixin below($value, $width: true) { | |
@if $width { | |
@media (max-width: em($value)) { | |
@content; | |
} | |
} @else { | |
@media (max-height: em($value)) { | |
@content; | |
} | |
} | |
} | |
@mixin between($minValue, $maxValue, $width: true) { | |
$minValue: em($minValue); | |
$maxValue: em($maxValue); | |
@if $width { | |
$from: '(min-width: #{$minValue})'; | |
$to: '(max-width: #{$maxValue})'; | |
$media: $from + ' and ' + $to; | |
@media #{$media} { | |
@content; | |
} | |
} @else { | |
$from: '(min-height: #{$minValue})'; | |
$to: '(max-height: #{$maxValue})'; | |
$media: $from + ' and ' + $to; | |
@media #{$media} { | |
@content; | |
} | |
} | |
} | |
// $Convert Pixels to Ems | |
@function em($pixels, $context: $browserContext) { | |
@if (unitless($pixels)) { $pixels: $pixels * 1px; } | |
@if (unitless($context)) { $context: $context * 1px; } | |
@return $pixels / $context * 1em; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment