使用@font-face加载特殊字体

@font-face {
        font-family: MgOpen Modata;
        src:url(/fonts/MgOpenModataRegular.eot);
}
如IE下的使用方案
@font-face {
    font-family: "Century Gothic";
    src: url(../fonts/CenturyGothic.eot)
}
@font-face {
    font-family: "Century Gothic Bold";
    src: url(../fonts/CenturyGothicBold.eot)
}
firefox下的写法如下:
@font-face {
    font-family: "Century Gothic";
    src: url(../fonts/CenturyGothic.ttf) format("truetype");
}

@font-face {
    font-family: "Century Gothic Bold";
    src: url(../fonts/CenturyGothicBold.ttf) format("truetype");
}
用法:
<!--[if IE]>
<link rel="stylesheet" href="style/iefont.css" type="text/css" />
<![EndIf]-->
判断是ie时用如上的样式表

<html>
<head>
<style>@font-face { font-family:comic; src:url(http://valid_url/some_font_file.eot); }</style>
</head>
<body>
<p style="font-family:comic;font-size:18pt "> This paragraph uses the font-face rule defined in the above style element. The rule embeds an OpenType file for the Comic Sans font. </p>
</body>
</html>
fire下用ttf,ie下用eot

【第一步】
获取要使用字体的三种文件格式,确保能在主流浏览器中都能正常显示该字体。
.TTF或.OTF,适用于Firefox 3.5、Safari、Opera
.EOT,适用于Internet Explorer 4.0+
.SVG,适用于Chrome、IPhone
下面要解决的是如何获取到某种字体的这三种格式文件。一般地,我们在手头上(或在设计资源站点已经找到)有该字体的某种格式文件,最常见的是.TTF文件,我们需要通过这种文件格式转换为其余两种文件格式。字体文件格式的转换可以通过网站FontsQuirrel或onlinefontconverter提供的在线字体转换服务获取。这里推荐第一个站点,它允许我们选择需要的字符生成字体文件(在服务的最后一个选项),这样就大大缩减了字体文件的大小,使得本方案更具实用性。
【第二步】
获取到三种格式的字体文件后,下一步要在样式表中声明该字体,并在需要的地方使用该字体。
字体声明如下:
@font-face { font-family: 'fontNameRegular'; src: url('fontName.eot'); src:local('fontName Regular'), local('fontName'), url('fontName.woff') format('woff'),url('fontName.ttf') format('truetype'), url('fontName.svg#fontName') format('svg'); }
在页面中需要的地方使用该字体:
p { font: 13px fontNameRegular, Arial, sans-serif; } h1{font-family: fontNameRegular}
或者
<p style="font-family: fontNameRegular">掬水月在手,落花香满衣</p>


转载于:https://my.oschina.net/sharesuiyue/blog/479959

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值