嵌入web字体
@font-face模块
可以帮助我们轻松解决Web页面中使用优雅字体的方式,而且我们可以根据需要自定义多种字体,但是每个@font-face只能定义一种,若需要多个字体就启用多个@font-face规则。
@font-face 主要就是把自己想要的,或者自己定义的Web字体嵌入到Web页面中,然后这些字体就会被放置在服务器上,浏览器会根据指定的命令将对应的字体下载到本地缓存,使用它来修饰文本。也就是我们所说的Web字体嵌入。
| 描述符 | 值 | 描述 |
|---|---|---|
| font-family | name | 必需。规定字体的名称。 |
| src | URL | 必需。定义字体文件的 URL。 |
| font-stretch |
| 可选。定义如何拉伸字体。默认是 "normal"。 |
| font-style |
| 可选。定义字体的样式。默认是 "normal"。 |
| font-weight |
| 可选。定义字体的粗细。默认是 "normal"。 |
| unicode-range | unicode-range | 可选。定义字体支持的 UNICODE 字符范围。默认是 "U+0-10FFFF"。 |

TrueType
Windows和Mac系统最常用的字体格式,其最大的特点就是它是由一种数学模式来进行定义的基于轮廓技术的字体,这使得它们比基于矢量的字体更容易处理,保证了屏幕与打印输出的一致性。同时,这类字体和矢量字体一样可以随意缩放、旋转而不必担心会出现锯齿。
EOT– Embedded Open Type (.eot)
EOT是嵌入式字体,是微软开发的技术。允许OpenType字体用@font-face嵌入到网页并下载至浏览器渲染,存储在临时安装文件夹下。
OpenType(.otf)
OpenType是微软和Adobe共同开发的字体,微软的IE浏览器全部采用这种字体。致力于替代TrueType字体。
WOFF–WebOpen Font Format (.woff)
WOFF(Web开发字体格式)是一种专门为了Web而设计的字体格式标准,实际上是对于TrueType/OpenType等字体格式的封装,每个字体文件中含有字体以及针对字体的元数据(Metadata),字体文件被压缩,以便于网络传输。
SVG(Scalable Vector Graphics) Fonts (.svg)
SVG是由W3C制定的开放标准的图形格式。SVG字体就是使用SVG技术来呈现字体,还有一种gzip压缩格式的SVG字体。
兼容所有浏览器的声明方法:
1 2 3 4 5 6 7 8 9 10 | @font-face { font-family: 'icomoon'; src:url('../font/icomoon.eot'); /* IE9兼容模式 */ src:url('../font/icomoon.eot?#iefix') format('embedded-opentype'), /* IE6~IE8 */ url('../font/icomoon.woff') format('woff'), /* 现代浏览器 */ url('../font/icomoon.ttf') format('truetype'),/* safari,Android,ios */ url('../font/icomoon.svg#icomoon') format('svg'); /* Legacy ios */ font-weight: normal; font-style: normal;} |
示例:
index.html
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><link rel="stylesheet" href="../css/stylesheet.css" /><style>div{font-family: amadeus_regularamadeusRg;}</style></head><body><div>staven</div></body></html>
stylesheet.css
@font-face {font-family: 'amadeus_regularamadeusRg';src: url('../fonts/amadeus-webfont.eot');src: url('../fonts/amadeus-webfont.eot?#iefix') format('embedded-opentype'),url('../fonts/amadeus-webfont.woff2') format('woff2'),url('../fonts/amadeus-webfont.woff') format('woff'), url('../fonts/amadeus-webfont.ttf') format('truetype'), url('../fonts/amadeus-webfont.svg#amadeus_regularamadeusRg') format('svg');font-weight: normal;font-style: normal;}
导入小图标字体
index.html
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><link rel="stylesheet" href="../css/style.css" /></head><body><div class="icon-firefox"></div></body></html>
style.css
@font-face {font-family: 'icomoon';src:url('../fonts/icomoon.eot?7gr0ck');src:url('../fonts/icomoon.eot?7gr0ck#iefix') format('embedded-opentype'),url('../fonts/icomoon.ttf?7gr0ck') format('truetype'),url('../fonts/icomoon.woff?7gr0ck') format('woff'),url('../fonts/icomoon.svg?7gr0ck#icomoon') format('svg');font-weight: normal;font-style: normal;}[class^="icon-"], [class*=" icon-"] {/* use !important to prevent issues with browser extensions that change fonts */font-family: 'icomoon' !important;speak: none;font-style: normal;font-weight: normal;font-variant: normal;text-transform: none;line-height: 1;/* Better Font Rendering =========== */-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;}.icon-film:before {content: "\e900";}.icon-envelop:before {content: "\1f313";}.icon-smile2:before {content: "\e902";}.icon-chrome:before {content: "\e903";}.icon-firefox:before {content: "\e901";}.icon-IE:before {content: "\e904";}.icon-opera:before {content: "\e905";}.icon-safari:before {content: "\e906";}.icon-IcoMoon:before {content: "\e907";}

浙公网安备 33010602011771号