当您您找到或购买到希望使用的字体时,可将该字体文件存放到 web 服务器上,它会在需要时被自动下载到用户的计算机上。
您"自己的"的字体是在 CSS3 @font-face 规则中定义的。
在新的 @font-face 规则中,您必须首先定义字体的名称(比如 myFirstFont),然后指向该字体文件。
如需为 HTML 元素使用字体,请通过 font-family 属性来引用字体的名称 (myFirstFont)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
@font-face{
font-family:myFirstFont;
src: url(calibrid.ttf);
}
@font-face{
font-family:myFirstFont;
src: url(calibriz.ttf);
font-weight:bold;
}
div{
font-family:myFirstFont;
}
</style>
<title>无标题文档</title>
</head>
<body>
<div>
这是font-face测试~~ <b> 这是font-face测试~~</b> 这是font-face测试~~
</div>
</body>
</html>
注意:
使用粗体字体
您必须为粗体文本添加另一个包含描述符的 @font-face:
效果图: