简体   繁体   English

相对路径对嵌入CSS字体无效吗?

[英]Relative paths not valid for embedding fonts with CSS?

I'm trying to embed a font, the way I always do with the CSS generated by FontSquirrel, only with a relative path: 我试图嵌入字体,就像我一直使用FontSquirrel生成的CSS一样,只使用相对路径:

@font-face {
    font-family: 'MyFontFamily';
    src: url('config/templates/fonts/MyFont.eot');
    src: url('config/templates/fonts/MyFont.eot?#iefix') format('embedded-opentype'),
     url('config/templates/fonts/MyFont.woff') format('woff'),
     url('config/templates/fonts/MyFont.ttf') format('truetype'),
     url('config/templates/fonts/MyFont.svg#MyFont') format('svg');
    font-weight: normal;
    font-style: normal;
}

This does not seem to work. 这似乎不起作用。

Changing it to /base/config/templates/fonts... fixes the problem, but for the sake of the application, it would be preferable to use relative paths. 将其更改为/base/config/templates/fonts...解决此问题,但是对于应用程序而言,最好使用相对路径。

The font files do exist relative to the document that is using them. 字体文件确实相对于使用它们的文档存在。

Are relative paths for font importing just not acceptable? 字体导入的相对路径是否不可接受? What's going on here? 这里发生了什么?

Change it to: 更改为:

./config/templates/fonts/...

Or in some cases: 或在某些情况下:

../config/templates/fonts/...

Depending on your structure. 根据您的结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM