Skip to content

Instantly share code, notes, and snippets.

@matiassingers
Last active December 26, 2015 02:29
Show Gist options
  • Save matiassingers/7079477 to your computer and use it in GitHub Desktop.
Save matiassingers/7079477 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.1)
// Compass (v0.13.alpha.7)
// ----
$magic-number: 24px
$size: 9px
@function round-to($number, $precision)
@return round($number / $precision) * $precision
@function calculateEm($target, $context: $magic-number)
$emSize: 0
@if $target == 0
@return $emSize
@if $target > $context
@if $target < ($context * 2)
$emSize: ($context * 2) / $target
@else if $target < ($context * 3)
$emSize: ($context * 3) / $target
@else
$emSize: $context / $target
@return round-to($emSize + 0em, 0.0001)
test
value: calculateEm($size)
type-value: type-of(calculateEm($size))
type-test-1: type-of(1.54839em)
test-1: calculateEm($size) == 2.67em
test-1: calculateEm($size) == 2.667em
test-1: calculateEm($size) == 2.6667em
test-2: calculateEm($size) == calculateEm($size)
test-1
t-1-1: round-to(5.55555, 0.1) == 5.5
t-1-2: round-to(5.55555, 0.1) == 5.6
t-1-3: round-to(5.55555, 0.1) == round-to(5.55555, 0.1)
test-01
t-01-1: round-to(5.55555, 0.01) == 5.55
t-01-2: round-to(5.55555, 0.01) == 5.56
t-01-3: round-to(5.55555, 0.01) == round-to(5.55555, 0.01)
test-001
t-001-1: round-to(5.55555, 0.001) == 5.555
t-001-2: round-to(5.55555, 0.001) == 5.556
t-001-3: round-to(5.55555, 0.001) == round-to(5.55555, 0.001)
test-0001
t-0001-1: round-to(5.55555, 0.0001) == 5.5555
t-0001-2: round-to(5.55555, 0.0001) == 5.5556
t-0001-3: round-to(5.55555, 0.0001) == round-to(5.55555, 0.0001)
test {
value: 2.6667em;
type-value: number;
type-test-1: number;
test-1: false;
test-1: false;
test-1: true;
test-2: true;
}
test-1 {
t-1-1: false;
t-1-2: false;
t-1-3: true;
}
test-01 {
t-01-1: false;
t-01-2: false;
t-01-3: true;
}
test-001 {
t-001-1: false;
t-001-2: true;
t-001-3: true;
}
test-0001 {
t-0001-1: false;
t-0001-2: true;
t-0001-3: true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment