Skip to content

Instantly share code, notes, and snippets.

@seajones
Last active December 21, 2015 06:08
Show Gist options
  • Select an option

  • Save seajones/6261618 to your computer and use it in GitHub Desktop.

Select an option

Save seajones/6261618 to your computer and use it in GitHub Desktop.
Easy conversion of px to ems
// First, set a base size in the document - do this on HTML, or BODY, I tend towards HTML
html {
font-size: $base-font;
}
// Generally somewhere else (my SCSS is more structured than this, put this function (somewhere before you're going to use it)
@function ems($p, $b: $base-font) {
@return ($p / $b) * 1em; /* Because SASS/SCSS allows you to mix units, you can calculate this proportion in pixels, and then just multiply by 1em to get the o/p in ems */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment