2015-09-27 35 views
3

我99.9%肯定我有这个权利,但由于某种原因,它不工作。字体不能在扩展名为

我做了一个将CSS注入页面的chrome扩展,我的CSS一直工作正常,直到我想改变字体。

所以我的表现有这个...

"css": ["css/my-custom.css"], 
"js": [ "js/jquery.js", "js/my-custom.js", "js/jquery.cookie.js"], 
"web_accessible_resources": ["css/my-custom.css", "fonts/Roboto-Regular.ttf", "images/*.*"] 

...和我的CSS有这...

@font-face { 
    font-family: 'RobotoLtRegular'; 
    src: url('chrome-extension://[email protected]@extension_id__/fonts/Roboto-Regular.ttf'); 
    font-weight: normal; 
    font-style: normal; 
} 

body { 
    background: #f1f1f1 !important; 
    font-size: 1.2em !important; 
    font-family: RobotoLtRegular !important; 
} 

p { 
    font-family: RobotoLtRegular !important; 
} 

...然而,当我重新载入我的分机我不t看到新的字体。铬元素检查器还显示该字体应该是body和p上显示的字体(没有其他字体覆盖RobotoLtRegular。

仅供参考我的字体存储在扩展的css目录中,所以路径是正确的。

我在一个完全丧失

任何建议将是有益的

更新:如果它有助于了解,我加载它作为一个正在开发的扩展

+0

尝试在font-face url之后添加'format(“truetype”)''。 – wOxxOm

+0

好,但网络选项卡说什么?作为@ font-face,字体仍然需要资源加载,那么它是什么?该扩展资源URL是否有效? –

回答

1

解决的办法是web_accessible_resources添加到清单(作品清单第2版):

"web_accessible_resources": ["*.ttf" ] 

要包括你可以用逗号分开它们的方式的任何其他文件类型:

"web_accessible_resources": [ "*.png", "*.ttf" ] 

厂完美。

+0

但是等一下。你已经在你的问题的片段中有过。 – Xan

+0

我认为他在content_scripts键中使用了web_accessible_resources键。这就是最初没有起作用的原因。 –

-1

字体 - >。/fonts/*

@font-face { 
    font-family: 'FontAwesome'; 
    src: url('fonts/fontawesome-webfont.eot?v=4.3.0'); 
    src: url('fonts/fontawesome-webfont.eot?#iefix&v=4.3.0') format('embedded-opentype'), url('fonts/fontawesome-webfont.woff2?v=4.3.0') format('woff2'), url('fonts/fontawesome-webfont.woff?v=4.3.0') format('woff'), url('fonts/fontawesome-webfont.ttf?v=4.3.0') format('truetype'), url('fonts/fontawesome-webfont.svg?v=4.3.0#fontawesomeregular') format('svg'); 
    font-weight: normal; 
    font-style: normal; 
} 

没有其他配置需要。