kumar004
kumar004

Reputation: 337

Remove space between value and units. SASS

A SCSS function written for converting pixel to rem generates a space between value and unit. How to avoid the space. Details mentioned in the URL give below.

jsfiddle domain + /9pe5a1kx/1/

Upvotes: 0

Views: 462

Answers (1)

Hans Spieß
Hans Spieß

Reputation: 935

Use this function:

@function px2em($px, $metric: 'em', $base-font-size: 16px) {
  @if unitless($px) {
    @warn "Assuming #{$px} to be in pixels, attempting to convert it into pixels.";
    @return px2em($px * 1px, $metric, $base-font-size);
  } @else if unit($px) == em {
    @return $px;
  }
  @return #{($px / $base-font-size) + $metric};
}

Upvotes: 1

Related Questions