Created
June 2, 2015 02:22
-
-
Save nguyenj/46dd88c6c732e875afa2 to your computer and use it in GitHub Desktop.
A simple and basic SASS media query breakpoint mixin.
This file contains 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
// 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