Recherche…


Convertir px en (r) em

Pour convertir px en em ou rem, vous pouvez utiliser la fonction suivante:

@function rem-calc($size, $font-size : $font-size) {
    $font-size: $font-size + 0px;
    $remSize: $size / $font-size;
    @return #{$remSize}rem;
}

@function em-calc($size, $font-size : $font-size) {
    $font-size: $font-size + 0px;
    $remSize: $size / $font-size;
    @return #{$remSize}em;
}

La $font-size est la $font-size la police d'origine.

Par exemple:

$font-size: 14;

body {
  font-size: #{$font-size}px;
  font-size: rem-calc(14px); // returns 1rem
  // font-size: rem-calc(28); // returns 2rem
}


Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow