Skip to content

Instantly share code, notes, and snippets.

@soundstep
Last active June 26, 2017 02:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soundstep/abad27d4ac44682b0d05 to your computer and use it in GitHub Desktop.
Save soundstep/abad27d4ac44682b0d05 to your computer and use it in GitHub Desktop.
SASS Font calculation
<body>
<div class="test">Hello</div>
</body>
@import "compass/css3";
$base-font-size: 16px !default;
$base-line-height: 16px !default;
$default-unit: 1rem !default; // 1px or 1em or 1rem
$px-fallback: true !default; // Adds fallback px values for old browsers when using rems
/**
* @functon value
*
* Given a px value, returns it in the default unit
*
* Parameters:
* $px-value: The px value
* $baseline-px: Unit to output the value in
* $default-unit: The font-size on the HTML element
*/
@function value($px-value, $baseline-px: $base-font-size, $default-unit: $default-unit) {
// Convert the baseline into rems
$baseline-rem: $baseline-px / $default-unit;
@return if($px-value == 0, $px-value, $px-value / $baseline-rem);
}
.test {
font-size: value(100px);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment