我不明白这里发生了什么,因为当我自己拥有这段代码时,它正在工作(在 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
不管用。我尝试重新排列顺序(首先定义第二种字体),但它仍然不起作用。所以现在我相信我的字体文件有问题,所以我会尝试获取另一个副本,看看情况如何。
Update:
代码似乎没有什么问题。我使用 FireBug 对 fonts.css 文件进行源代码编辑,当我将“mmfont2”的 url 重命名为“mmfont.ttf”(第一个字体的 URL)时,它更新了页面并加载了字体,但是当我将其重命名为“mmfont2.ttf”,它又恢复为浏览器的默认字体。所以我现在确信这是字体文件的问题而不是代码的问题。
看来我使用的第二种字体不是网络兼容字体。有趣的是,事实证明,同一种字体还有另一个别名“Century Gothic”,它是一种网络安全字体,可以在所有浏览器中使用,甚至无需链接任何文件!
(我不知道我是否应该关闭或删除这个问题)
/脚本/字体.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