2014-03-06 129 views
1

我有下面的CSS(按n SASS生成):字体不呈现?

@font-face { 
    font-family: "locust"; 
    src: url(/assets/LOCUST.TTF) format("truetype"); 
    src: url(/assets/LOCUST.svg) format("svg"); } 

的路径似乎访问 - 我在localhost:3000并通过键入localhost:3000/assets/LOCUST.TTF,例如,如果我可以下载/看字体。

但是火狐不会使字体:

<h1 style="font-family: locust;">Test</h1> 

我使用Rails,但我不认为这个问题是相关的,因为生成的HTML和CSS似乎是正确的我,和字体是可访问的。如果我知道我需要产生什么,我很可能会知道如何解决。

+1

尝试为FF获取WOFF字体。 https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face – Kooki3

回答

0

资产URL

这里的代码中,我们使用:

#app/assets/stylesheets/fonts.css.scss 
@font-face { 
    font-family: 'Lato'; 
    src: asset_url('layout/fonts/lato/lato-hairline-webfont.eot'); 
    src: asset_url('layout/fonts/lato/lato-hairline-webfont.eot?#iefix') format('embedded-opentype'), 
     asset_url('layout/fonts/lato/lato-hairline-webfont.woff') format('woff'), 
     asset_url('layout/fonts/lato/lato-hairline-webfont.ttf') format('truetype'), 
     asset_url('layout/fonts/lato/lato-hairline-webfont.svg#latohairline') format('svg'); 
    font-weight: 100; 
    font-style: normal; 
} 

通知asset_url使用 - 这提供给URL(所以为什么你不能够在CSS兼容的路径访问路径)


网络字体

如果你有使用的字体充分的权利,你最好在这里使用web字体生成器:http://www.fontsquirrel.com/tools/webfont-generator

这将创建跨浏览器的web字体文件.tff.woff.svg.eot格式