弃用警告:在 calc() 之外使用 / 进行除法已被弃用,并将在 Dart Sass 2.0.0 中删除

发布于 2025-01-09 18:11:12 字数 1232 浏览 0 评论 0原文

在这些函数中,我将 rem 编译为 px 并将 em 编译为 px

$base: 16 !default;

@function scut-strip-unit ($num) {
  @return $num / ($num * 0 + 1);
}

@function rem ($pixels) {
  @return scut-strip-unit($pixels) / $base * 1rem;
}
@function em ($pixels, $context: $base) {
    @return #{$pixels/$context}em;
  }

但是使用 Sass v1.49,我们面临这个错误:

Error
Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in 
Dart Sass 2.0.0.

Recommendation: math.div(scut-strip-unit($pixels), $base) or calc(scut-strip-unit($pixels) / $base)

More info and automated migrator: https://sass-lang.com/d/slash-div

  ╷
8 │   @return scut-strip-unit($pixels) / $base * 1rem;
  │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵

Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in 
Dart Sass 2.0.0.

Recommendation: math.div($pixels, $context) or calc($pixels / $context)

More info and automated migrator: https://sass-lang.com/d/slash-div

   ╷
11 │     @return #{$pixels/$context}em;
   │               ^^^^^^^^^^^^^^^^
   ╵
   

In these functions I compile rem to px and em to px:

$base: 16 !default;

@function scut-strip-unit ($num) {
  @return $num / ($num * 0 + 1);
}

@function rem ($pixels) {
  @return scut-strip-unit($pixels) / $base * 1rem;
}
@function em ($pixels, $context: $base) {
    @return #{$pixels/$context}em;
  }

But with Sass v1.49, we are facing this error:

Error
Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in 
Dart Sass 2.0.0.

Recommendation: math.div(scut-strip-unit($pixels), $base) or calc(scut-strip-unit($pixels) / $base)

More info and automated migrator: https://sass-lang.com/d/slash-div

  ╷
8 │   @return scut-strip-unit($pixels) / $base * 1rem;
  │           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  ╵

Deprecation Warning: Using / for division outside of calc() is deprecated and will be removed in 
Dart Sass 2.0.0.

Recommendation: math.div($pixels, $context) or calc($pixels / $context)

More info and automated migrator: https://sass-lang.com/d/slash-div

   ╷
11 │     @return #{$pixels/$context}em;
   │               ^^^^^^^^^^^^^^^^
   ╵
   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑕疵 2025-01-16 18:11:12

将不再支持使用 /calc 函数之外进行除法。以下是文档中的原因概述:

Sass 目前在某些上下文中将 / 视为除法运算,在其他上下文中将其视为分隔符。这使得 Sass 用户很难判断任何给定的 / 的含义,并且很难使用使用 / 作为分隔符的新 CSS 功能。

您应该使用 sass:math 中的 math.div

@use "sass:math";

body {
  font-size: math.div(50, 16) * 1px;
}

或者在 calc 中使用 /

body {
  font-size: calc(50 / 16) * 1px;
}

Using / to make divisions outside of calc function will not be supported anymore. Here is an overview of the reasons why from the documentation:

Sass currently treats / as a division operation in some contexts and a separator in others. This makes it difficult for Sass users to tell what any given / will mean, and makes it hard to work with new CSS features that use / as a separator.

You should either use math.div from sass:math:

@use "sass:math";

body {
  font-size: math.div(50, 16) * 1px;
}

Or use / inside calc:

body {
  font-size: calc(50 / 16) * 1px;
}
掩耳倾听 2025-01-16 18:11:12

为了避免使用 sass:math,你可以使用

calc(scut-strip-unit($pixels) / $base)

To avoid using sass:math, you may just use

calc(scut-strip-unit($pixels) / $base)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文