Skip to content

Instantly share code, notes, and snippets.

@alexwoollam
Last active January 30, 2019 11:22
Show Gist options
  • Save alexwoollam/55060878944f9728b06c5dce3e276d80 to your computer and use it in GitHub Desktop.
Save alexwoollam/55060878944f9728b06c5dce3e276d80 to your computer and use it in GitHub Desktop.
Neat media query in sass
// Breakpoints (this map lives in variables).
$breakpoint:(
'xxsmall': 400px, // max-width
'xsmall': 400px, // min-width...
'small': 600px,
'medium': 1000px,
'large': 1200px,
'xlarge': 1400px,
'xxlarge': 1600px,
);
/*
* To use:
* @include media('xxsmall'){...width: 100%; etc...} <-xxsmall is locked.
* @include media('xsmall'){...width: 50%; etc...} <-xsmall is smallest itteration.
* @include media('small'){...width: 100%; etc...} <- anything higher overwrites the rule set in lower itteration.
* e.g. media('xlarge') is already {...width: 100%; etc...} so its not needed.. unless it needs a new size, e.g.:
* @include media('xlarge'){...width: 200%; etc...} <- so width is now 100% on xxsmall, 50% on xs,s,m,l and 200% on xl & xxl.
*/
// Media queries... normally lives in the mixins file.
@mixin media($break) {
$value: map-get($breakpoints, $break);
$xxsmall: map-get($breakpoint, 'xxsmall');
@if $value < $xxsmall {
@media (max-width: $value){
@content;
}
}//@if xxsmall
@else {
@media (min-width: $value){
@content;
}
}//@if xsmall
}
@mixin full-width {
width: 100%;
float: none;
clear: both;
}
@mixin small-full {
@media (max-width: $breakpoint-xxsmall) {
@include full-width;
} // @media small
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment