带有Assetic的Synmfony 2中的CSS文件中的@ font-face规则

时间:2015-03-18 09:36:34

标签: css symfony fonts assetic

我正在寻找使用Assetic在Symfony中包含CSS文件的字体。问题是浏览器无法加载这些字体。

@font-face {
font-family: 'Corbert'; /*a name to be used later*/
src:    url('fonts/Corbert-Regular.otf')  format('opentype'),
        url('fonts/Corbert-Regular.woff') format('woff'),
        url('fonts/Corbert-Regular.ttf') format('truetype');
}

我的路径结构是

...  
+-src/  
| +-MyCompany/  
|   +-MyBundle/  
|     +-Resources/  
|       +-public/  
|         +-css/  
|           +-fonts/  

我链接CSS文件的路径是

path into css file

enter image description here

enter image description here 我做错了什么?

1 个答案:

答案 0 :(得分:3)

我找到了解决方案:

只需输入您链接css文件的Document.html.twig:

<style type="text/css">
  @font-face {
  font-family: 'Corbert'; 
  src:    url({{asset('fonts/Corbert-Regular.otf')}}) format('opentype'), 
    url({{asset('fonts/Corbert-Regular.woff')}}) format('woff'),
    url({{asset('fonts/Corbert-Regular.otf')}}) format('truetype');
  }
</style>

确实如果你把它放在css文件中,symfony似乎不会识别代码。图片也是如此:

<style type="text/css">
  body, html{
    background-image:url({{ asset('images/wallpaper.png') }});
  }
<style>

美好的周末!

相关问题