资产管道、指南针字体和eot?iefix调用字体

5
我正在尝试使用Compass字体混合器,其中包含*.eot?iefix的引用。
我的app/assets/fonts包含所有所需的字体类型,包括.eot。
当我尝试运行assets:precompile任务时,该任务失败并显示以下信息:webfont.eot?iefix没有预编译。
你知道这个问题可能的解决方案吗?
如果config.assets.compile = true,则不会出现错误,但据我了解,在生产环境中最好不要使用它。
3个回答

10

你也可以只用纯 Scss 实现它:

@font-face {
  font-family: 'DroidSans';
  src: url(font-path('DroidSans-webfont.eot'));
  src: url(font-path('DroidSans-webfont.eot') + '?#iefix') format('embedded-opentype'),
       url(font-path('DroidSans-webfont.woff')) format('woff'),
       url(font-path('DroidSans-webfont.ttf')) format('truetype'),
       url(font-path('DroidSans-webfont.svg') + '#DroidSansRegular') format('svg');
  font-weight: normal;
  font-style: normal;
}

我们可以使用 font-url() 代替 url(font-path()) - Dzung Nguyen
1
我相信你现在可以了。当时Sass助手和Rails助手之间存在冲突。 - Aaron Gibralter

4
我刚刚用一个小技巧(被支持的)解决了这个问题。
我创建了一个新的CSS文件font.css.erb,并在@font-face声明的位置放置了@import "font"
@font-face {
    font-family: 'SketchBlockBold';
    src: font_url('font/sketch_block-webfont.eot');
    src: url('<%= asset_path('font/sketch_block-webfont.eot')+"?#iefix" %>') format('embedded-opentype'),
         font_url('font/sketch_block-webfont.woff') format('woff'),
         font_url('font/sketch_block-webfont.ttf') format('truetype'),
         url('<%= asset_path('font/sketch_block-webfont.svg')+"#SketchBlockBold" %>') format('svg');
    font-weight: normal;
    font-style: normal;
}

请注意资产路径的使用以及特殊文件结尾的连接。

你为什么同时使用 font-urlurl 声明?它们有什么区别? - pruett
这是因为url()不是资产管道函数,但font_url()是。在这种情况下,我基本上用erb中的东西替换了font_url()的魔法。 - Michael Gall
谢谢您的建议!代码在本地运行得非常好,但是“rake assets:precompile”仍然出现了相同的错误:“fontname.eot未预编译”。您认为可能是什么问题呢? - lyuba

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接