【发布时间】:2012-10-26 07:57:30
【问题描述】:
我注意到在使用网络字体时,它们最初可能需要一秒钟才能出现;就像您创建一个下拉导航菜单一样,当您第一次将鼠标悬停在菜单上时,整个菜单将显示为背景颜色一秒钟,然后出现文本。
这并不理想,它让我相信加载 CSS 文件时并没有下载 webfonts,而是在您第一次在页面上查看它们时下载。
但另一方面,我已经在我的电脑上安装了字体,因此不需要下载它们,因此提出了一个问题,即他们为什么要这样做!?
这是我用来加载网络字体的 CSS:
@font-face {
font-family: 'Roboto';
src: url('../fonts/Roboto-Regular-webfont.eot');
src: url('../fonts/Roboto-Regular-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/Roboto-Regular-webfont.woff') format('woff'),
url('../fonts/Roboto-Regular-webfont.ttf') format('truetype'),
url('../fonts/Roboto-Regular-webfont.svg#RobotoRegular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Roboto';
src: url('../fonts/Roboto-Italic-webfont.eot');
src: url('../fonts/Roboto-Italic-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/Roboto-Italic-webfont.woff') format('woff'),
url('../fonts/Roboto-Italic-webfont.ttf') format('truetype'),
url('../fonts/Roboto-Italic-webfont.svg#RobotoItalic') format('svg');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'Roboto';
src: url('../fonts/Roboto-Bold-webfont.eot');
src: url('../fonts/Roboto-Bold-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/Roboto-Bold-webfont.woff') format('woff'),
url('../fonts/Roboto-Bold-webfont.ttf') format('truetype'),
url('../fonts/Roboto-Bold-webfont.svg#RobotoBold') format('svg');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'Roboto';
src: url('../fonts/Roboto-Light-webfont.eot');
src: url('../fonts/Roboto-Light-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/Roboto-Light-webfont.woff') format('woff'),
url('../fonts/Roboto-Light-webfont.ttf') format('truetype'),
url('../fonts/Roboto-Light-webfont.svg#RobotoLight') format('svg');
font-weight: 300;
font-style: normal;
}
@font-face {
font-family: 'Roboto';
src: url('../fonts/Roboto-Medium-webfont.eot');
src: url('../fonts/Roboto-Medium-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/Roboto-Medium-webfont.woff') format('woff'),
url('../fonts/Roboto-Medium-webfont.ttf') format('truetype'),
url('../fonts/Roboto-Medium-webfont.svg#RobotoMedium') format('svg');
font-weight: 500;
font-style: normal;
}
【问题讨论】:
-
你能发布你用来加载字体的代码吗?
-
@BillyMoat 抱歉,现在发布。 :)
-
使用
src: local()。另见:stackoverflow.com/questions/12312323/… -
您的字体系列名称不应该是 Roboto、RobotoItalic 和 RobotoBold 之类的吗?在调用字体时,您是否还指定了诸如“Roboto”、Helvetica、Arial、sans-serif 之类的内容?
-
@BillyMoat 对于你的后一个问题,是的,我是。对于你以前的问题,不,这样做意味着当网络字体下载失败并且字体应该是粗体时,你会遇到问题。见:stackoverflow.com/questions/12562631/…