Last active
August 29, 2015 14:14
-
-
Save Darep/8f49b931aceea3d270fb to your computer and use it in GitHub Desktop.
Sass breakpoints
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
// Get value from a Sass list of key-value items (helper function) | |
@function match($collection, $key) { | |
@each $item in $collection { | |
$index: index($item, $key); | |
@if $index { | |
$return: if($index == 1, 2, $index); | |
@return nth($item, $return); | |
} | |
} | |
@return false; | |
} | |
$breakpoints: | |
small 568px, | |
narrow 768px, | |
standard 984px, | |
modern 1240px, | |
wide 1400px; | |
/* | |
Usage: @include breakpoint(narrow); | |
$point Name of breakpoint from $breakpoints list, or exact breakpoint in pixels etc. | |
$type Use max-width or min-width query; default is 'min', invert by supplying 'max' | |
*/ | |
@mixin breakpoint($point, $type: 'min', $unit: 1px) { | |
$bp: match($breakpoints, $point); | |
$modifier: 0; | |
@if $type == 'max' { | |
$modifier: $unit; | |
} | |
@if $bp == false { | |
$bp: $point; | |
} | |
@media (#{$type}-width: $bp - $modifier) { | |
@content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment