2016-07-20 4 views
0

변환 된 EM 값을 3 자리 (예 : 1.36em)로 제한하려면 em() 변환 함수를 편집하는 방법은 무엇입니까?CSS SASS로 변환 된 십진수

input.scss

@function em($target, $context: $font___base-size) { 
    @return ($target/$context) * 1em; 
} 
body {font-size:em(15px);} 

body { 
    font-family: sans-serif; 
    font-size: 1.36364em; } 

답변

0

output.css 사용 round()ceil() 또는 floor() 그래서 같은

round(($target/$context)*100)/100; 

100이 될 수있는 임의의 수의 10^N 여기서, n은 원하는 소수 자릿수.

Sass-lang documentation on round()

+0

감사 루카스, 내가 'pxtoem'으로 정확하게 작동하는 나의 기능을 수정 : – codeMama

0

나는이 같은 갈 것이다 :

// Configuration 
$font___base-size : 11px; 
$number-of-digits : 2; 

// Function 
@function em($target, $digits : $number-of-digits, $context: $font___base-size) { 
    $n : 1; 
    @if $digits > 0 { 
     @for $i from 1 through $digits { 
      $n : $n * 10; 
     } 
    } 
    @return round(($target/$context) * $n)/$n * 1em; 
} 

// Example use 
body { 
    font-size:em(15px); 
} 

출력 :

body { 
    font-size: 1.36em; 
} 
관련 문제