Created
March 8, 2017 18:44
-
-
Save iamravenous/b75fac6497a30dc98465f25a98f137ed to your computer and use it in GitHub Desktop.
Mobile-first breakpoints and mediaqueries mixins
This file contains hidden or 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
// Functions | |
@function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) { | |
$n: index($breakpoint-names, $name); | |
@return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null); | |
} | |
@function breakpoint-min($name, $breakpoints: $grid-breakpoints) { | |
$min: map-get($breakpoints, $name); | |
@return if($min !=0, $min, null); | |
} | |
@function breakpoint-max($name, $breakpoints: $grid-breakpoints) { | |
$next: breakpoint-next($name, $breakpoints); | |
@return if($next, breakpoint-min($next, $breakpoints) - 1px, null); | |
} | |
// Mixins | |
@mixin media($name, $breakpoints: $grid-breakpoints) { | |
$min: breakpoint-min($name, $breakpoints); | |
@if $min { | |
@media (min-width: $min) { | |
@content; | |
} | |
} @else { | |
@content; | |
} | |
} | |
@mixin media-down($name, $breakpoints: $grid-breakpoints) { | |
$max: breakpoint-max($name, $breakpoints); | |
@if $max { | |
@media (max-width: $max) { | |
@content; | |
} | |
} @else { | |
@content; | |
} | |
} | |
// Breakpoints Map | |
$grid-breakpoints: ( | |
xs: 0, | |
sm: 544px, | |
md: 768px, | |
lg: 992px, | |
xl: 1200px | |
) !default; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment