在scss中使用math.div代替/

需要使用 math.div 而不是斜杠重写此函数。下面给出的 URL 中提到的详细信息。(由于一些格式问题无法在此处发布代码)

jsfiddle 域 + /26ty5aj7

@return #{($px / $base-font-size) + $metric};

回答

这是具有更新语法的函数。确保将@use导入保留在文件的顶部。

@use "sass:math";

@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;
  }
  $test: #{math.div($px, $base-font-size) + $metric};
  @return $test;
}

// Pixels to rem based on sass-mq
@function px2rem($px) {
  @if unit($px) == rem {
    @return $px;
  }

  @return px2em($px, 'rem');
}

  • 从 [docs](https://sass-lang.com/documentation/break-changes/slash-div#automatic-migration),还有一个自动迁移工具:`npm install -g sass-migrator` 然后`sass-migrator 划分 **/*.scss` `

以上是在scss中使用math.div代替/的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>