我试图使用@font-face
CSS属性定义本地我的ttf字体如下:如何正确使用font-weight和font-style来声明CSS font-face?
开sans.css
@font-face {
font-family: 'Open Sans';
src: url('OpenSans-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url('OpenSans-Bold.ttf') format('truetype');
font-weight: bold;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url('OpenSans-BoldItalic.ttf') format('truetype');
font-weight: bold;
font-style: italic;
}
@font-face {
font-family: 'Open Sans';
src: url('OpenSans-Light.ttf') format('truetype');
font-weight: lighter;
font-style: normal;
}
@font-face {
font-family: 'Open Sans';
src: url('OpenSans-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
}
@font-face {
font-family: 'Open Sans';
src: url('OpenSans-ExtraBold.ttf') format('truetype');
font-weight: bolder;
font-style: normal;
}
但不幸的是,它不工作,并且浏览器(Iceweasel 38.6.1)总是向我显示最后一个(特别粗体)。我也跟着this answer,这似乎是迄今为止最好的一个。
我做错了什么?
P.S.
我需要在本地使用打开三世字体面,没有任何互联网连接,所以谷歌字体API不脚在我的情况。
编辑
ttf
文件是在CSS的同一目录下;- open-sans.css作为第一个CSS文件导入;
在页面文本字体属性是:
font-family: "Open Sans",sans-serif; font-size: 14px;
但它总是加载在CSS中声明的最后一个。
你有没有下载并保存在你的文件夹中的字体? –
是的。字体全部到位。我添加了更多信息。 – sentenza