教程 > css3 教程 > 阅读:84

css3 字体——迹忆客-ag捕鱼王app官网

css3-font


css3 @font-face 规则

使用以前 css 的版本,网页设计师不得不使用用户计算机上已经安装的字体。

使用 css3,网页设计师可以使用他/她喜欢的任何字体。

当你发现您要使用的字体文件时,只需简单的将字体文件包含在网站中,它会自动下载给需要的用户。

您所选择的字体在新的 css3 版本有关于 @font-face 规则描述。

您"自己的"的字体是在 css3 @font-face 规则中定义的。


浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

属性
@font-face 4.0 9.0 3.5 3.2 10.0

internet explorer 9 , firefox, chrome, safari, 和 opera 支持 woff (web open font format) 字体.

firefox, chrome, safari, 和 opera 支持 .ttf(true type字体)和.otf(opentype)字体字体类型)。

chrome, safari 和 opera 也支持 svg 字体/折叠.

internet explorer 同样支持 eot (embedded opentype) 字体.

注意: internet explorer 8 以及更早的版本不支持新的 @font-face 规则。


使用您需要的字体

在新的 @font-face 规则中,您必须首先定义字体的名称(比如 myfirstfont),然后指向该字体文件。

lamp 提示:url请使用小写字母的字体,大写字母在ie中会产生意外的结果

如需为 html 元素使用字体,请通过 font-family 属性来引用字体的名称 (myfirstfont):

@font-face
{
    font-family: myfirstfont;
    src: ;
}
 
div
{
    font-family:myfirstfont;
}

使用粗体文本

您必须添加另一个包含粗体文字的@font-face规则:

@font-face
{
    font-family: myfirstfont;
    src: ;
    font-weight:bold;
}

该文件"sansation_bold.ttf"是另一种字体文件,包含sansation字体的粗体字。

浏览器使用这一文本的字体系列"myfirstfont"时应该呈现为粗体。

这样你就可以有许多相同的字体@font-face的规则。


css3 字体描述

下表列出了所有的字体描述和里面的@font-face规则定义:

描述符 描述
font-family name 必需。规定字体的名称。
src url 必需。定义字体文件的 url。
font-stretch
  • normal
  • condensed
  • ultra-condensed
  • extra-condensed
  • semi-condensed
  • expanded
  • semi-expanded
  • extra-expanded
  • ultra-expanded
可选。定义如何拉伸字体。默认是 "normal"。
font-style
  • normal
  • italic
  • oblique
可选。定义字体的样式。默认是 "normal"。
font-weight
  • normal
  • bold
  • 100
  • 200
  • 300
  • 400
  • 500
  • 600
  • 700
  • 800
  • 900
可选。定义字体的粗细。默认是 "normal"。
unicode-range unicode-range 可选。定义字体支持的 unicode 字符范围。默认是 "u 0-10ffff"。

查看笔记

扫码一下
查看教程更方便
网站地图