// Convert from pixels to em // @param {integer} $px - Number of pixels to be converted. // @param {integer} $base-font-size - Default value for 1em in browser. // // Usage: em(12px); @function em($px, $base-font-size: 16px) {
@if (unitless($px)) { @warn "Assuming #{$px} to be in pixels, attempting to convert it into pixels for you"; @return px2em($px + 0px); // That may fail. } @else if (unit($px) == em) { @return $px; } @return ($px / $base-font-size) * 1em;
}