aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/css/@font-face/src/index.html
blob: e209486348a629db55c88309a1395bc591929304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
title: src
slug: Web/CSS/@font-face/src
translation_of: Web/CSS/@font-face/src
---
<div>{{CSSRef}}</div>

<p>{{cssxref("@font-face")}} 中的src描述符指定了包含字体数据的资源<code>@font-face</code> 规则中需要指定这个属性</p>

<p>它的值是一个有优先级的以逗号分割的外部引用或者本地安装的字体名称当需要使用字体时用户代理指浏览器的意思将会使用以逗号分隔的参考集中能成功激活的第一个参考值如果是包含无效数据的字体或者本地的字体资源不存在用户代理将会忽略当前字体并且加载下一个字体</p>

<p>与CSS中的其他URL一样URL可以是相对的在这种情况下它相对于包含@ font-face规则的样式表的位置进行解析对于SVG字体URL指向文档中定义的包含SVG字体的元素如果省略元素引用则默认引用第一个定义字体同样字体容器只加载<code>@font-face</code> 规则给定的其中一种字体片段标识符用于指示要加载的字体如果容器格式缺少定义的片段标识符方案将会使用一个简单的基于1的索引方案e.g., "font-collection#1" for the first font, "font-collection#2" for the second font, etc.</p>

<p>{{cssinfo}}</p>

<h2 id="Syntax">Syntax</h2>

<pre class="brush: css">/* &lt;url&gt; values */
src: url(https://somewebsite.com/path/to/font.woff); /* Absolute URL */
src: url(path/to/font.woff);                         /* Relative URL */
src: url(path/to/font.woff) format("woff");          /* Explicit format */
src: url('path/to/font.woff');                       /* Quoted URL */
src: url(path/to/svgfont.svg#example);               /* Fragment identifying font */

/* &lt;font-face-name&gt; values */
src: local(font);      /* Unquoted name */
src: local(some font); /* Name containing space */
src: local("font");    /* Quoted name */

/* Multiple items */
src: local(font), url(path/to/font.svg) format("svg"),
     url(path/to/font.woff) format("woff"),
     url(path/to/font.otf) format("opentype");
</pre>

<h3 id="Values">Values</h3>

<dl>
 <dt><code>&lt;url&gt; [ format( &lt;string&gt;# ) ]?</code></dt>
 <dd>Specifies an external reference consisting of a {{cssxref("&lt;url&gt;")}}, followed by an optional hint using the <a id="format()" name="format()"><code>format()</code></a> function to describe the format of the font resource referenced by that URL. The format hint contains a comma-separated list of format strings that denote well-known font formats. If a user agent doesn't support the specified formats, it skips downloading the font resource. If no format hints are supplied, the font resource is always downloaded.</dd>
 <dt><code>&lt;font-face-name&gt;</code></dt>
 <dd>Specifies the name of a locally-installed font face using the <a id="local()" name="local()"><code>local()</code></a> function, which uniquely identifies a single font face within a larger family. The name can optionally be enclosed in quotes.</dd>
</dl>

<h3 id="Formal_syntax">Formal syntax</h3>

<pre class="syntaxbox">{{csssyntax}}</pre>

<h2 id="Examples">Examples</h2>

<pre class="brush: css">@font-face {
  font-family: examplefont;
  src: local(Example Font),
       url('examplefont.woff') format("woff"),
       url('examplefont.otf') format("opentype");
}
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSS3 Fonts', '#src-desc', 'src')}}</td>
   <td>{{Spec2('CSS3 Fonts')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("css.at-rules.font-face.src")}}</p>