问题
给定代码的 CSS 输出不会生成类(-f-font-Audimat
和-f-font-Jura
) 本身,只是字体块。所以你的代码只是生成这个:
@font-face {
font-family: "Audimat";
src: url(../assets/fonts/Audimat.ttf),url(../assets/fonts/Audimat.otf),url(../assets/fonts/Audimat.eot);
}
@font-face {
font-family: "Jura";
src: url(../assets/fonts/Jura.ttf),url(../assets/fonts/Jura.otf),url(../assets/fonts/Jura.eot);
}
您可以通过以下两种方式更正:
选项1
保持你当前显示的 mixin,并将font-family
定义直接添加到类定义中(缺点,它有重复的代码)。
较少的
.-f-font-Audimat {
font-family: "Audimat";
@font-face {
.-f-font("Audimat");
}
}
.-f-font-Jura {
font-family: "Jura";
@font-face {
.-f-font("Jura");
}
}
CSS 输出
.-f-font-Audimat {
font-family: "Audimat";
}
@font-face {
font-family: "Audimat";
src: url(../assets/fonts/Audimat.ttf),url(../assets/fonts/Audimat.otf),url(../assets/fonts/Audimat.eot);
}
.-f-font-Jura {
font-family: "Jura";
}
@font-face {
font-family: "Jura";
src: url(../assets/fonts/Jura.ttf),url(../assets/fonts/Jura.otf),url(../assets/fonts/Jura.eot);
}
选项 2
更改您的 mixin 以动态创建所有字体定义,包括类名,并在没有嵌套的情况下调用 mixin(缺点,LESS 中动态创建的类目前不能用作 mixin)。像这样:
较少的
.-f-font(@name) {
@className: ~"@{name}";
.-f-font-@{className} {
font-family: @name;
}
@font-face {
font-family: @name;
src:~"url(../assets/fonts/@{name}.ttf),url(../assets/fonts/@{name}.otf),url(../assets/fonts/@{name}.eot)";
}
}
.-f-font("Audimat");
.-f-font("Jura");
CSS 输出- 与选项 #1相同。