@font-face嵌入字體
@font-face能夠載入伺服器端的字型文件,讓瀏覽器端可以顯示使用者電腦裡沒有安裝的字型。
語法:
@font-face {
font-family : 字体名称;
src : 字体文件在服务器上的相对或绝对路径;
}這樣設定之後,就可以像使用普通字體一樣在(font-*)中設定字體樣式。
例如:
p {
font-size :12px;
font-family : "My Font"; /*必须项,设置@font-face中font-family同样的值*/}範例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>嵌入字体</title>
<style type="text/css">
@font-face{
font-family: "myFont";
src: url("http://www.imooc.com/Amaranth-BoldItalic.otf");
}
.demo {
width: 340px;
padding: 30px;
color: #566F89;
background: #000;
font-size:58px;
font-family: "myFont";
}
</style>
</head>
<body>
<div class="demo">myFont</div>
</body>
</html>效果:
加了字體的:



