HTML/Font/字体格式

来自康健生活
Kangkk​(留言 | 贡献)2023年3月16日 (四) 09:27的版本 (创建页面,内容为“ == 格式示例 == <blockquote> <syntaxhighlight lang="css"> @font-face { font-family: <font-name>; src: <local/url> <format>,[…]; font-weight: <font-weight>; font-style: <font-style>; font-stretch: <font-stretch>; unicode-range:<unicode-range>; } </syntaxhighlight></blockquote> 示例如下: <syntaxhighlight lang="css"> @font-face { font-family: 'Awesome Font'; font-style: normal; font-weight: 400; src: local('Awesome Font'), url…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

格式示例

@font-face {
  font-family: <font-name>;
  src: <local/url> <format>,[…];
  font-weight: <font-weight>;
  font-style: <font-style>;
  font-stretch: <font-stretch>;
  unicode-range:<unicode-range>;
}

示例如下:

@font-face {
  font-family: 'Awesome Font';
  font-style: normal;
  font-weight: 400;
  src: local('Awesome Font'),
    url('/fonts/awesome.woff2') format('woff2'), 
    url('/fonts/awesome.woff') format('woff'),
    url('/fonts/awesome.ttf') format('ttf'),
    url('/fonts/awesome.eot') format('eot');
}

可以将一个大的字体设置成小的子集(例如拉丁,希腊和斯拉夫字母等),并且只是加载这个子集来渲染页面上的字体。使用unicide range 子集并将文件分成字体不同样式的变体可以迅速和高效的下载用户“只需要”下载的子集和变体的字体。

指定一个逗号隔开的数据集合, 数据可以是下面三种形式中的任何一种:

  • Single codepoint (e.g. U+416)
  • Interval range (e.g. U+400-4ff): indicates the start and end codepoints of a range
  • Wildcard range (e.g. U+4??): ‘?’ characters indicate any hexadecimal digit
@font-face {
  font-family: 'Awesome Font';
  font-style: normal;
  font-weight: 400;
  src: local('Awesome Font'),
    url('/fonts/awesome-l.woff2') format('woff2'), 
    url('/fonts/awesome-l.woff') format('woff'),
    url('/fonts/awesome-l.ttf') format('ttf'),
    url('/fonts/awesome-l.eot') format('eot');
  unicode-range: U+000-5FF; /* Latin glyphs */
}
IE 浏览器
其他浏览器

WOFF

IE 浏览器 旧的浏览器不支持
其他浏览器 旧的浏览器不支持

EOT

IE 浏览器 支持 IE (版本<9)使用 EOT 变体
其他浏览器 不支持

TTF/OTF

IE 浏览器 部分支持
其他浏览器
安卓 支持 安卓(版本<4.4)使用 TTF 变体

SVG

兼容

https://caniuse.com/