WordPress 的 @font-face CSS 路径
使用 FontSquirrel 生成的 CSS 代码制作了网站的静态版本。 CSS 样式表位于“css”文件夹中,字体位于“fonts”文件夹中。显示 @font-face 相对路径的 CSS 示例块:
@font-face {
font-family: 'TitilliumText22LRegular';
src: url('../fonts/TitilliumText22L003-webfont.eot');
src: url('../fonts/TitilliumText22L003-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/TitilliumText22L003-webfont.woff') format('woff'),
url('../fonts/TitilliumText22L003-webfont.ttf') format('truetype'),
url('../fonts/TitilliumText22L003-webfont.svg#TitilliumText22LRegular') format('svg');
font-weight: normal;
font-style: normal;
}
调用
font-family: 'TitilliumText22LRegular', Verdana, sans-serif;
Now it's WordPress template time 一切正常。 WP 使用模板根样式表(“style.css”)。所以从逻辑上讲,如果我将字体存储在“fonts”文件夹中并删除“../”路径备份,我应该没问题,因为 WP 样式表位于根目录,并且其中的所有内容都应引用其自己的位置:
src: url('fonts/TitilliumText22L003-webfont.eot');
但这不起作用。后备字体系列和其他字体样式规则工作正常。 WP 样式表对于引用模板根目录下“img”文件夹中的图像的类似 CSS 路径结构没有任何问题。奇怪的是,如果我将字体文件本身移动到模板根目录并直接在样式表中引用它们,如下所示:
src: url('TitilliumText22L003-webfont.eot');
一切正常。当然,我不想在模板根目录中转储 40 多个字体文件。可能 WP 需要一些单独的 PHP 文件/规则,为此使用 URL 路径欺骗,例如 blog_info('template_url') 或类似的。但我希望我错过了一些明显的东西!
感谢您的任何想法
Did a static version of site using FontSquirrel-generated CSS code. CSS stylesheet in "css" folder, fonts in "fonts" folder. CSS sample chunk showing @font-face relative paths:
@font-face {
font-family: 'TitilliumText22LRegular';
src: url('../fonts/TitilliumText22L003-webfont.eot');
src: url('../fonts/TitilliumText22L003-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/TitilliumText22L003-webfont.woff') format('woff'),
url('../fonts/TitilliumText22L003-webfont.ttf') format('truetype'),
url('../fonts/TitilliumText22L003-webfont.svg#TitilliumText22LRegular') format('svg');
font-weight: normal;
font-style: normal;
}
Everything works fine with a call to
font-family: 'TitilliumText22LRegular', Verdana, sans-serif;
Now it's WordPress template time. WP uses a template root stylesheet ("style.css"). So logically, if I store the fonts in a "fonts" folder and just get rid of the "../" path backup, I should be OK, since the WP stylesheet is at root, and everything in it should be referenced to its own location:
src: url('fonts/TitilliumText22L003-webfont.eot');
But this does not work. Fallback font-families and other font style rules work fine. The WP stylesheet has no problems with the analogous CSS path structure referencing images in an "img" folder below the template root. Strangely, if I move the font files themselves up to the template root and reference them in the stylesheet directly like so:
src: url('TitilliumText22L003-webfont.eot');
everything works fine. Naturally though I don't want to dump 40+ font files in the template root. Possibly WP requires some separate PHP file/rule using URL path trickery for this, say blog_info('template_url') or similar. But I hope I'm missing something obvious instead!
thanks for any ideas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在主题目录(与
style 同一级别)添加单独的
)font-face
文件夹,其中包含字体和 font-face css(在我的示例中名为fonts.css
) .css也放弃字体名称的 all 前缀(没有
../
或/
)。在您的
header.php
文件中,您要添加:无论如何,适用于我的主题。
Add separate
font-face
folder containing the fonts and the font-face css (namedfonts.css
for my example) at the theme directory (same level asstyle.css
)Ditch all prefixes to the font names too (no
../
or/
).In your
header.php
file you want to add:Works for my theme at any rate.