@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>

效果:QQ截图20161014172202.png加了字体的:QQ截图20161014172207.png

继续学习
||
<!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>
提交重置代码
章节
笔记
提问
课件
反馈
捐赠

CSS3从入门到精通教程