Created
September 3, 2014 15:58
-
-
Save zboralski/da4ab58e8ad50dbc3d57 to your computer and use it in GitHub Desktop.
Responsive Scale
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
// Requires SASS >= 3.3 and responsive.scss | |
// https://gist.github.com/maxluster/168e650267bac9faaafd | |
// | |
// Scale value with $width for each $width in $named-breakpoints map. | |
// Usage : @include responsive("font-size", $base-font-size + px, | |
// resp-scale($base-width, $base-font-size)); | |
@function resp-scale($width, $value, $scale-up: false) { | |
$m : (); | |
@each $k, $v in $named-breakpoints { | |
$ok : true; | |
$v: $v / ($v * 0 + 1); // strip-units | |
@if $v > $width { | |
$ok : $scale-up; | |
} | |
@if $ok { | |
$res : round($v * $value / $width); | |
$m: map-merge($m, ("#{$k}": $res +'px')); | |
} | |
} | |
@return $m; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The cool thing is that if your properties are exclusively set in rem then the following @include is all you need to scale everything to any width!
If you want to scale up (when breakpoint width is greater than the base width), set the
$scale-up
argument to true.