【问题标题】:Incompatible units: 'rem' and 'px' - Bootstrap 4.3.1不兼容的单位:'rem' 和 'px' - Bootstrap 4.3.1
【发布时间】:2019-10-23 19:56:54
【问题描述】:

在自定义覆盖 sass 文件中覆盖 Bootstrap 4.3.1 变量时,我收到“不兼容的单位:'rem' 和 'px'”。

我已尝试按照 Bootstrap 4 文档中的说明将自定义 sass 文件的以下路径定位在文件顶部和文件的最后一行。

@import "node_modules/bootstrap/scss/functions"; 
@import "node_modules/bootstrap/scss/variables";
@import "node_modules/bootstrap/scss/mixins";

终端出错

ERROR in ./src/scss/main.scss (./node_modules/raw-loader!./node_modules/postcss-loader/lib??embedded!./node_modules/sass-loader/lib/loader.js??ref--14-3!./src/scss/main.scss)

Module build failed: 
$custom-select-feedback-icon-padding-right: calc((1em + #{2 * $custom-select-padding-y}) * 3 / 4 + #{$custom-select-padding-x + $custom-select-indicator-padding}) !default;
                                                                                                                                                                 ^
      Incompatible units: 'rem' and 'px'.

【问题讨论】:

  • 为什么是<br>?在 css 文件中?
  • 忽略
  • 你找到解决办法了吗?

标签: sass compiler-errors bootstrap-4


【解决方案1】:

首先从SCSS文件中删除<br>,这是calc()函数的问题而不是px or rem的问题。

注意

calc()函数是CSS的内置函数,所以当你在SCSS中调用calc()时,你需要使用#{}技术来使用变量

height: calc(100% - #{$body_padding})

现在我举一个例子

$custom-select-padding-y = 50px;
    
$custom-select-feedback-icon-padding-right: calc((1em +  #{2 * 50px}) * 3 / 4 + #{$custom-select-padding-x + $custom-select-indicator-padding}) !default;

2 * 50px = 100px 等之后,它无法计算1em + {random px} 所以,它的返回未定义和编译器给出错误。

calc() 计算 2 * 5px = 10px or 2 * 1rem = 32px

calc()无法计算2rem + 1em1rem + 1px

【讨论】:

    猜你喜欢
    • 2017-11-29
    • 2015-10-28
    • 2017-08-05
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 2018-08-04
    • 2016-11-23
    • 2014-03-11
    相关资源
    最近更新 更多