SASS 和@font-face
我有以下 CSS - 我如何在 SASS 中描述它?我尝试用 css2sass 反向编译它,但不断收到错误......这是我的 CSS (可以工作;-) )吗?
@font-face {
font-family: 'bingo';
src: url("bingo.eot");
src: local('bingo'),
url("bingo.svg#bingo") format('svg'),
url("bingo.otf") format('opentype');
}
I have the following CSS - how would I describe it in SASS? I've tried reverse compiling it with css2sass, and just keep getting errors.... is it my CSS (which works ;-) )?
@font-face {
font-family: 'bingo';
src: url("bingo.eot");
src: local('bingo'),
url("bingo.svg#bingo") format('svg'),
url("bingo.otf") format('opentype');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果有人想知道 - 这可能是我的 css...
将渲染为
看起来足够接近...只需要检查 SVG 渲染
In case anyone was wondering - it was probably my css...
will render as
which seems to be close enough... just need to check the SVG rendering
我已经为此苦苦挣扎了一段时间了。 Dycey 的解决方案是正确的,因为多次指定 src 会在 css 文件中输出相同的内容。然而,这似乎在 OSX Firefox 23 中出现问题(可能其他版本也是如此,但我没有时间测试)。
来自 Font Squirrel 的跨浏览器
@font-face
解决方案如下所示:生成带有逗号分隔值的 src 属性,您需要将所有值写在一行上,因为 Sass 不支持换行符。要生成上述声明,您需要编写以下 Sass:
我认为多次写出路径似乎很愚蠢,而且我不喜欢代码中的行太长,因此我通过编写此 mixin 来解决它:
用法:例如,我可以使用之前的 mixin 来设置 Frutiger Light 字体,如下所示:
I’ve been struggling with this for a while now. Dycey’s solution is correct in that specifying the
src
multiple times outputs the same thing in your css file. However, this seems to break in OSX Firefox 23 (probably other versions too, but I don’t have time to test).The cross-browser
@font-face
solution from Font Squirrel looks like this:To produce the
src
property with the comma-separated values, you need to write all of the values on one line, since line-breaks are not supported in Sass. To produce the above declaration, you would write the following Sass:I think it seems silly to write out the path a bunch of times, and I don’t like overly long lines in my code, so I worked around it by writing this mixin:
Usage: For example, I can use the previous mixin to setup up the Frutiger Light font like this:
对于那些寻找 SCSS mixin 的人,包括 woff2、SASS list.append 对于有条件地添加源文件/格式很有用:
$type
参数用于在$family
中定位不同的文件。如果您收到无法解析错误,请记住仔细检查您的字体目录 (
$dir
)。For those looking for an SCSS mixin instead, including woff2, SASS list.append is useful for conditionally adding source files/formats:
The
$type
parameter is used for locating different files within a$family
.If you get a can't resolve error, remember to double check your fonts directory (
$dir
).在我的例子中,我使用SASS Mixin:
用法:
结果:
In my case I use SASS Mixin:
Usage:
Result: