Created
May 4, 2013 10:18
-
-
Save lunelson/5517064 to your computer and use it in GitHub Desktop.
Strip() and Assert() functions; original version
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
// --- | |
// Breakpoint (v2.0.5) | |
// Sass (v3.2.8) | |
// --- | |
// fiddling with auto conversion between rem and px | |
$base-font-size: 16; | |
// remove and set units | |
@function remove-unit($n) { @return $n / ($n * 0 + 1); } | |
@function set-unit($n, $u) { @return remove-unit($n) * 1#{$u}; } | |
// aliases of above to "strip" and "assert" | |
@function strip($n) { @return remove-unit($n); } | |
@function assert($n, $u) { @return set-unit($n, $u); } | |
// px to rem and vice versa | |
@function px2rem($p) { @return assert($p / $base-font-size, rem); } | |
@function rem2px($r) { @return assert($r * $base-font-size, px); } | |
// tests | |
$mobile: px2rem(480); //480px | |
.test { | |
@include breakpoint($mobile) { | |
width: px2rem(100px); | |
} | |
} |
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
@media (min-width: 30rem) { | |
.test { | |
width: 6.25rem; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment