4

在 Symfony 2 中,我像这样使用资产捆绑。

{% stylesheets
            'bootstrap/css/bootstrap.css'
            'bootstrap/flat/css/flat-ui.css'
            filter='cssrewrite'
            filter='?yui_css'
%}

它工作得很好,但是我的@font-face 资源没有加载。它们在开发环境中运行良好,但是一旦在生产环境中将 css 捆绑到单个文件中,就会加载默认字体?

cssrewrite 工作正常,因为我检查了相对路径是否正确更新为指向正确的区域,我什至尝试使用无效的绝对 URL。

我尝试编译,但没有帮助。唯一有效的是将它从捆绑中删除,然后直接加载。

symfony 资产捆绑和@font-face :S :S :S 是否存在某种错误

下面是 @font-face 捆绑后在 prod 环境中的 css。

@font-face{font-family:"Flat-UI-Icons-16";src:url("../bootstrap/flat/fonts/Flat-UI-Icons-16.eot");src:url("../bootstrap/flat/fonts/Flat-UI-Icons-16.eot?#iefix") 
4

1 回答 1

0

There are some good information about URL in CSS files in this Stackoverflow page.

One of the response states that relative URLs within a CSS file are relative to the directory where the file is located.

If your font is loaded from

bootstrap/css/bootstrap.css

And the URLs within the CSS looks like the following relative URL:

../bootstrap/flat/fonts/Flat-UI-Icons-16.eot

That means the browser will try to get the font as following

bootstrap/bootstrap/flat/fonts/Flat-UI-Icons-16.eot

You probably want to try the following URL style

../../bootstrap/flat/fonts/Flat-UI-Icons-16.eot

Or

../flat/fonts/Flat-UI-Icons-16.eot

I would highly recommend the documentation about fixing css path with cssrewrite filter.

Note that if you use the cssrewrite filter you cannot use the @YourAwesomeBundle syntax.

I hope this will fix your issue

于 2013-03-22T05:00:06.160 回答