CSS Front-End Development SASS

Authored by Dustin Horton

1 Comment

Useful SASS Functions: Converting px to em units

Truthfully, I’m still just experimenting with moving font sizing & paddings to em units. A semi-recent post by Chris Coyier has me re-examining just how many times I reset font sizes in media queries, and contemplating if using ems could prevent this.

I wrote a simple function to return an em font size, based on a variable I set earlier called $font-size. I use that variable to set the font size on the body tag, and whenever I’m looking to reset the font size to it’s original value.

Just pass in the desired font size in pixels, and you’re returned an equivalent em value.