Take this function in Sass:
@function pem($pxval, $base: 16) { @return #{$pxval / $base}em ; }
(source: https://gist.github.com/2237465)
pem(16)
returns 1em
and it's ok, but pem(16px)
returns 1pxem
.
how can this function accept both types of input?
thanks
This seems like a good use for SASS's unitless() function.
@function pem($pxval, $base: 16) {
@if (unitless($pxval)) {
$pxval: $pxval * 1px;
}
@if (unitless($base)) {
$base: $base * 1px;
}
@return $pxval / $base * 1em;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With