我不明白这里发生了什么,因为当我自己拥有这段代码时,它可以正常工作(在 FireFox 中):
@font-face {
font-family: 'mmfont';
src: url('/scripts/mmfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
然后我以完全相同的方式添加了第二种字体,但只有第一种字体有效:
@font-face {
font-family: 'mmfont2';
src: url('/scripts/mmfont2.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
然后我使用字体生成器为 IE9 获取 EOT 文件并为我生成@font-face 代码,但现在这两种字体都无法在任何浏览器中使用(我尝试了 IE9、FF12、Chrome 和 Safari5)。
然后我将 @font-face CSS 放在它自己的“/scripts/fonts.css”文件中,这样字体和 CSS 就在同一个文件夹中,我尝试直接使用这两个 URL(“mmfont.ttf ') 和 webroot 文件夹 ('/scripts/mmfont.ttf'),但两种方法都不起作用。
我做错了什么?
更正:
我在调用第一个字体“mmfont”时出现了错别字,我这样做了:font-family: mm_font
但现在我修正了错字,再次只有第一个字体可以使用代码下面,第二个字体 mmfont2
不工作。我试图重新安排顺序(先定义第二种字体),但它仍然不起作用。所以现在我相信我的字体文件有问题,所以我会尝试获取另一个副本,看看情况如何。
更新:
代码好像没什么问题。我使用 FireBug 对 fonts.css 文件进行源代码编辑,当我将“mmfont2”的 url 重命名为“mmfont.ttf”(第一种字体的 URL)时,它更新了页面和加载的字体,但是当我将它重新命名为“mmfont2.ttf”,它又回到了浏览器的默认字体。所以我现在确定这是字体文件而不是代码的问题。
我使用的第二种字体似乎不是网络兼容字体。有趣的是,事实证明,一直以来,同一种字体都有另一个别名“Century Gothic”,这是一种网络安全字体,可以在所有浏览器中使用,甚至无需链接任何文件!!
(我不知道是否应该关闭或删除此问题)
/scripts/fonts.css
@CHARSET "ISO-8859-1";
@font-face {
font-family: 'mmfont';
src: url('/scripts/mmfont.eot');
src: url('/scripts/mmfont.eot?#iefix') format('embedded-opentype'),
url('/scripts/mmfont.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'mmfont2';
src: url('/scripts/mmfont2.eot');
src: url('/scripts/mmfont2.eot?#iefix') format('embedded-opentype'),
url('/scripts/mmfont2.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
/index.html
<link rel="StyleSheet" href="/scripts/fonts.css" type="text/css">
目录
/
/index.html
/scripts/
/scripts/mmfont.ttf
/scripts/mmfont.eot
/scripts/mmfont2.ttf
/scripts/mmfont2.eot
/scripts/fonts.css
最佳答案
我们无法找到其他解决方法,因为我们在 Amazon 上的所有设置似乎都没有问题。相反,我们只是将字体定义本身嵌入到 data-uri 调用中,如下所示。由于 StackOverflow 中答案的大小限制,许多字体定义已被省略,但这应该让您对我们的方法有一个很好的了解。
@font-face {
font-family: "PFDinTextPro-Light";
src: url("233cd7_2_0-webfont.eot");
}
@font-face {
font-family: "PFDinTextPro-Light";
font-style: normal;
font-weight: normal;
src: url("233cd7_2_0-webfont.eot?#iefix") format("embedded-opentype"), url("data:application/x-font-woff;charset=utf-8;base64,d09GRgABAAAAAFq4ABEAAAAAmrQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABgAAAABwAAAAcYqvy...dRcDMyMXA5M2mM+m4LqJvRPKYQVy2CKhHBYgh9USyuGAaJOCaeMESnLMgHAYN3BBDecFinIdZ9LeyOxWBuTyALm8+XAuN5DLEwjn8oGM5Kr/zwAX4Qcq4HsC5woAufy1MG7kBhFtANGLRQMAAVB7j+oAAA==") format("woff"), url("233cd7_2_0-webfont.ttf") format("truetype");
}
关于html - @font-face 根本不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11343558/