Skip to content

Instantly share code, notes, and snippets.

@nguyenj
Created June 2, 2015 02:22
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 nguyenj/46dd88c6c732e875afa2 to your computer and use it in GitHub Desktop.
Save nguyenj/46dd88c6c732e875afa2 to your computer and use it in GitHub Desktop.
A simple and basic SASS media query breakpoint mixin.
// Usages:
// div {
// @include media(800px) {
// ...
// }
// }
//
// Or with a customized breakpoint:
// $tall: break(min-height 600px);
// div {
// @include media($tall) {
// ...
// }
// }
//
// Or a combination:
// $wide: break(min-width 800px);
// $tall: break(min-height 600px);
// div {
// @include media($wide, $tall) {
// ...
// }
// }
@function break($query) {
@if length($query) > 1 {
@return nth($query, 1) + ': ' + nth($query, 2);
}
@return 'min-width: ' + $query;
}
@mixin media($viewports...) {
$media-query: 'screen';
@each $view in $viewports {
$media-query: $media-query + ' and (' + $view +')';
}
@media #{$media-query} {
@content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment