不兼容的单位:“ rem”和“ px”-Bootstrap 4.3.1

时间:2019-06-08 18:20:46

标签: sass compiler-errors bootstrap-4

在自定义覆盖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'.

1 个答案:

答案 0 :(得分:0)

首先从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等。

相关问题