Skip to content

Instantly share code, notes, and snippets.

@lunelson
Created May 4, 2013 10:18
Show Gist options
  • Save lunelson/5517064 to your computer and use it in GitHub Desktop.
Save lunelson/5517064 to your computer and use it in GitHub Desktop.
Strip() and Assert() functions; original version
// ---
// 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);
}
}
@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