【发布时间】: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