CSS3 使用自定义字体_html/css_WEB-ITnose

php中文网
发布: 2016-06-24 11:33:12
原创
1428人浏览过

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前端: 

Gnomic智能体平台
Gnomic智能体平台

国内首家无需魔法免费无限制使用的ChatGPT4.0,网站内设置了大量智能体供大家免费使用,还有五款语言大模型供大家免费使用~

Gnomic智能体平台 47
查看详情 Gnomic智能体平台
HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号