【问题标题】:SASS syntax error: Undefined variable: "$em-base"SASS 语法错误:未定义变量:“$em-base”
【发布时间】:2014-04-11 07:17:49
【问题描述】:

我正在关注一个新的SASS structure guide here

尝试使用 PX 到 EM 混合,似乎变量没有通过。 但我有 base 导入 mixins,而 typography 是最后导入的。

主 SASS 文件:

// Modules and Variables
@import "modules/base";

// Partials
@import "partials/normalize";
@import "partials/typography";

BASE.scss:

@import "colors";
@import "fonts";
@import "animation";
@import "mixins";

_mixins.scss:

/* PIXELS to EM */
// eg. for a relational value of 12px write em(12) when the parent is 16px
// if the parent is another value say 24px write em(12, 24)

// @include em(12);
@function em($pxval, $base: $em-base) {
    @if not unitless($pxval) {
        $pxval: strip-units($pxval);
    }
    @if not unitless($base) {
        $base: strip-units($base);
    }
    @return ($pxval / $base) * 1em;
}

最后是 _typography.scss:

// widget table headers
section header h1 {
    font-family: LatoRegular;
    font-size: em(18);
}

来自 CodeKit 的错误:

Syntax error: Undefined variable: "$em-base".
    on line 6 of /assets/sass/partials/_typography.scss
    from line 38 of /assets/sass/dashboard.scss

【问题讨论】:

  • 不错的文章。戴尔是个好人!您可以尝试将您的 sass 放入 sassmeister.com,这样您就可以看到哪里出错了......
  • 当然你需要像这样初始化你的 $em-base 变量:$em-base: 16; // Default。见gist.github.com/ngryman/5077672
  • 啊失败了!大声笑我真正的em-base为em undefined

标签: sass mixins


【解决方案1】:

$em-base 未在您的任何文件中定义。

【讨论】:

  • 该死,忘了设置那个变量,一开始没看到$em-base: 16;
猜你喜欢
  • 2015-05-25
  • 2019-05-08
  • 1970-01-01
  • 1970-01-01
  • 2021-04-29
  • 2012-10-30
  • 2013-04-11
  • 2015-02-02
  • 2020-03-15
相关资源
最近更新 更多