Last active
August 29, 2015 14:03
-
-
Save sethlopezme/c74b1e5aeb139c4b78cf to your computer and use it in GitHub Desktop.
Updated breakpoint mixin to account for multiple types of media queries in one.
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
@mixin bp($queries, $type: only screen) { | |
$query-count: length($queries); | |
$media-statement: "#{$type} and"; | |
@for $i from 1 through $query-count { | |
$query: nth($queries, $i); | |
$value: ''; | |
$key: ''; | |
@if length($query) == 1 or nth($query, 2) == up { | |
$key: min-width; | |
$value: if(map-has-key($bp, nth($query, 1)), px-em(map-get($bp, nth($query, 1))), px-em(nth($query, 1))); | |
} @else { | |
@if nth($query, 2) == down { | |
$key: max-width; | |
$value: if(map-has-key($bp, nth($query, 1)), px-em(map-get($bp, nth($query, 1)) - 1), px-em(nth($query, 1) - 1)); | |
} @else { | |
$key: nth($query, 1); | |
$value: nth($query, 2); | |
} | |
} | |
$media-statement: if($i == 1, "#{$media-statement} (#{$key}: #{$value})", "#{$media-statement}, (#{$key}: #{$value})"); | |
} | |
@media #{$media-statement} { | |
@content; | |
} | |
} |
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
@function px-em($px, $px-context: 16) { | |
// Make sure it's a number | |
@if(round($px)) { | |
@return #{$px / $px-context}em; | |
} | |
} |
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
$bp: ( | |
S: 320 | |
M: 768, | |
L: 960 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment