Skip to content

Instantly share code, notes, and snippets.

@lucianobarauna
Forked from premregmi/px-to-rem.scss
Created December 2, 2020 21:12
Show Gist options
  • Save lucianobarauna/45dbd6d876a57474d5013f1e3945683f to your computer and use it in GitHub Desktop.
Save lucianobarauna/45dbd6d876a57474d5013f1e3945683f to your computer and use it in GitHub Desktop.
PX TO REM FUNCTION in SASS - Convert px value to rem easily in SASS
// SASS FUNCTION TO CONVERT PX INTO REM
// Defining base font size
// The default font size for html is 16px
$base-size: 16;
//Function to convert px value into rem
//You can replace rem with any other value you want (rem is most preferred value for web)
@function size($target, $context: $base-size) {
@return ($target / $context) * 1em;
}
// Let's use the size whenever you want
body {
margin: size(20);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment