A Pen by Romuald Quantin on CodePen.
Last active
June 26, 2017 02:50
-
-
Save soundstep/abad27d4ac44682b0d05 to your computer and use it in GitHub Desktop.
SASS Font calculation
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
<body> | |
<div class="test">Hello</div> | |
</body> |
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
@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