Skip to content

Instantly share code, notes, and snippets.

@mikem33
Created March 12, 2019 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikem33/cd17d9a7f129b8b8df009f23f75e6bd8 to your computer and use it in GitHub Desktop.
Save mikem33/cd17d9a7f129b8b8df009f23f75e6bd8 to your computer and use it in GitHub Desktop.
Media Queries Sass Mixins
// $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