Convert PX to EM in SCSS
When developing responsive websites it is important to use a non absolute unit. Em is perfect for this as its relative to the base font size. If like me, you grew up using PX and find it hard to think purely in em's then this function is for you!
@function em($target, $context: $baseFontSize) {
@if $target == 0 { @return 0 }
@return $target / $context + 0em;
}
// Usage:</p>
```
h1 {
font-size: em(50px, 18px);
}
```
Written by John Kilpatrick
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Scss
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#