@font-face(css3属性)实如今网页中嵌入随意字体

@font-face语法规则

@font-face {
   font-family: <YourWebFontName>;
   src: <source> [<format>][,<source> [<format>]]*;
   [font-weight: <weight>];
   [font-style: <style>];
 }

说明:

  1. YourWebFontName:此值指的就是你自己定义的字体名称。最好是使用你下载的默认字体。他将被引用到你的Web元素中的font-family。

    如“font-family:"YourWebFontName";”

  2. source:此值指的是你自己定义的字体的存放路径,能够是相对路径也能够是绝路径;

format:此值指的是你自己定义的字体的格式,主要用来帮助浏览器识别,其值主要有下面几种类型:truetype,opentype,truetype-aat,embedded-opentype,avg等;weight和style:这两个值大家一定非常熟悉。weight定义字体是否为粗体,style主要定义字体样式,如斜体。

实例:(以SingleMaltaRegular为例)

  1. 下载所须要的字体。

  2. 获得@font-face所需的.eot,.woff,.ttf,.svg字体格式字体。能够在这个站点上搞定。点击进入 (fontsquirrel)

  3. Font Squirrel下载文件到本地的电脑上了,解压。就可以得到字体。

  4. 在项目中新建目录fonts,讲下载字体放进去。

样式书写格式:

@font-face {
   font-family: 'SingleMaltaRegular';   
   src: url('../fonts/singlemalta-webfont.eot');  
   src: url('../fonts/singlemalta-webfont.eot?#iefix') format('embedded-opentype'),      
   url('../fonts/singlemalta-webfont.woff') format('woff'),   
   url('../fonts/singlemalta-webfont.ttf') format('truetype'),    
   url('../fonts/singlemaltawebfont.svg#SingleMaltaRegular') format('svg');   font-weight: normal;   font-style: normal;}


最后就可以引用的字体:

body{
  font-family: 'SingleMaltaRegular'
}

注:通过站点下载的文件中。会自己主动生成样式,从而直接拷贝就可以

原文地址:https://www.cnblogs.com/lcchuguo/p/5070811.html