Skip to content

Instantly share code, notes, and snippets.

@Darep
Last active August 29, 2015 14:14
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 Darep/8f49b931aceea3d270fb to your computer and use it in GitHub Desktop.
Save Darep/8f49b931aceea3d270fb to your computer and use it in GitHub Desktop.
Sass breakpoints
// 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