CSS3 使用自定义字体

CSS3 @font-face 规则

在 CSS3 之前,web 设计师必须使用已在用户计算机上安装好的字体。
通过 CSS3,web 设计师可以使用他们喜欢的任意字体。
当您您找到或购买到希望使用的字体时,可将该字体文件存放到 web 服务器上,它会在需要时被自动下载到用户的计算机上。
您“自己的”的字体是在 CSS3 @font-face 规则中定义的。


Firefox、Chrome、Safari 以及 Opera 支持 .ttf (True Type Fonts) 和 .otf (OpenType Fonts) 类型的字体。
Internet Explorer 9+ 支持新的 @font-face 规则,但是仅支持 .eot 类型的字体 (Embedded OpenType)。
注释:Internet Explorer 8 以及更早的版本不支持新的 @font-face 规则。


使用您需要的字体
在新的 @font-face 规则中,您必须首先定义字体的名称(比如 myFirstFont),然后指向该字体文件。
如需为 HTML 元素使用字体,请通过 font-family 属性来引用字体的名称 (hoverTreeFont).

先查看效果:http://hovertree.com/texiao/css/5.htm

完整HTML代码:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>CSS3自定义字体 - 何问起</title><base target="_blank"/>
    <meta charset="utf-8" />
    <style>
    @font-face {
        font-family: hoverTreeFont;
        src: url('http://hovertree.com/themes/fonts/Sansation_Light.ttf'),url('http://hovertree.com/themes/fonts/Sansation_Light.eot'); /* IE9+ */
    }

    @font-face {
        font-family: hoverTreeFont;
        src: url('http://hovertree.com/themes/fonts/Sansation_Bold.ttf'),url('http://hovertree.com/themes/fonts/Sansation_Bold.eot'); /* IE9+ */
        font-weight: bold;
    }

    .hvtbold {
        font-family: hoverTreeFont;
    }
    .hvtbold a{font-family: hoverTreeFont;}a{color:blue}
    div{font-size:16px;font-family:Arial, Sans-Serif,NSimSun,"\5b8b\4f53";border:1px solid green;margin:5px;}
</style>
</head>
<body>
    
    
    <div class="hvtbold">
        加了自定义字体的效果:<br /><br />

        With CSS3, websites can <b>finally</b> use fonts other than the pre-selected "web-safe" fonts.
        <br /><br />何问起 hovertree.com <br /><br /><b>柯乐义http://keleyi.com</b><br /><br /><a href="http://hovertree.com/down/">ASP.NET CMS源代码下载</a><br />
<br /><a href="http://hovertree.com/hvtart/bjae/is0xr36t.htm">原文</a> <a href="http://hovertree.com/">首页</a> <a href="http://hovertree.com/down/">更多特效</a>
    </div>
    
    <div>没加自定义字体的效果:<br /><br />

        With CSS3, websites can <b>finally</b> use fonts other than the pre-selected "web-safe" fonts.
        <br /><br />何问起 hovertree.com <br /><br /><b>柯乐义http://keleyi.com</b><br /><br /><a href="http://hovertree.com/down/">ASP.NET CMS源代码下载</a><br />
<br /><a href="http://hovertree.com/hvtart/bjae/is0xr36t.htm">原文</a> <a href="http://hovertree.com/">首页</a> <a href="http://hovertree.com/down/">更多特效</a>
    </div>

</body>
</html>

web前端: http://www.cnblogs.com/jihua/p/webfront.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值