如果条件<大于操作>需要您的 SCSS 帮助

Need your Help for SCSS if condition <greater than operation>

提问人:Arka Bhattacharjee 提问时间:2/18/2021 最后编辑:Arka Bhattacharjee 更新时间:2/18/2021 访问量:899

问:

我在尝试编译以下 SASS 代码时遇到编译错误: 你能帮我解决问题吗?

@mixin high {
   @if (calc(100% * 1.3333 + 0px) > 900px) {
     min-height: auto !important;
   }
  @else {
    min-height: 100% !important;
  }
}

.main-content {
  .container-fluid {
    @include high;
  }
}
sass gulp-sass scss-mixins sass-loader

评论


答:

1赞 Brebber 2/18/2021 #1

该函数是一个 css 函数,它将直接在浏览器中执行,而不是在 SASS 中执行。calc()

您可以将此表达式编写到 sass,但它将被解释为“写入 css 的代码”,因此 css 可以在浏览器中执行它,但不能直接在 sass 中执行它。

因此,您出错的原因是:

您尝试在指令中使用 calc() 作为函数来比较预期结果是否大于一个值。但是由于 SASS 不执行 calc(),因此它将其理解为不允许的操作。@if

解释示例:

// SASS
   border-radius: calc(1px + 1px);

// --> will become in css
  border-radius: calc(1px + 1px);

// but not
   border-radius: 2px;

请参见:https://sass-lang.com/documentation/syntax/special-functions#calc-clamp-element-progid-and-expression