如何使用web fonts?

1.将你的字体上传到服务器

建议将字体文件与你的css文件放在同一个文件夹中;或者将这些字体文件放在一个单独的文件夹中,并命名为fonts,然后把该文件夹与你的css文件放在同一个位置。 将这些字体文件放在.css文件附近的好处是使我们在编辑CSS时更容易映射到这些字体文件。

2.在css文件中增加@font-face规则

这样做是在CSS文件中创建字体的名称,以便当我们使用该字体时,知道在哪里可以找到字体文件,并允许用户的浏览器加载和显示它们。将@ font-face选择器放在CSS文件顶部,然后再放置其他CSS。 声明@ font-face选择器时,我们将指定字体的名称,放置不同字体文件的url以及字体的样式。

如下声明了两个字体:

@font-face {
    font-family: 'On-AirInline';
    src: url('fonts/on-air-inline-webfont.eot');
    src: url('fonts/on-air-inline-webfont.eot?#iefix') format('embedded-opentype'),
         url('fonts/on-air-inline-webfont.woff') format('woff'),
         url('fonts/on-air-inline-webfont.ttf') format('truetype'),
         url('fonts/on-air-inline-webfont.svg#On-AirInline') format('svg');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'On-AirRegular';
    src: url('fonts/on-air-regular-webfont.eot');
    src: url('fonts/on-air-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('fonts/on-air-regular-webfont.woff') format('woff'),
         url('fonts/on-air-regular-webfont.ttf') format('truetype'),
         url('fonts/on-air-regular-webfont.svg#OnAirRegular') format('svg');
    font-weight: normal;
    font-style: normal;
}

3.在css中使用声明的字体

接下来,就可以在你的css选择器中应用上面的字体啦:

h1 {
    font-family: 'On-AirRegular';
}
h2 {
    font-family: 'On-AirInline';
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值