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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
---
title: '@font-face'
slug: Web/CSS/@font-face
tags:
- CSS
- CSS Reference
- CSS 參考
- Fonts
- WOFF
- 字型
translation_of: Web/CSS/@font-face
---
<div>{{CSSRef}}</div>
<h2 id="摘要">摘要</h2>
<p>The <code>@font-face</code> <a href="/en-US/docs/CSS" title="CSS">CSS</a> <a href="/en-US/docs/CSS/At-rule" title="At-rule">at-rule</a> allows authors to specify online fonts to display text on their web pages. By allowing authors to provide their own fonts, <code>@font-face</code> eliminates the need to depend on the limited number of fonts users have installed on their computers. The <code>@font-face</code> at-rule may be used not only at the top level of a CSS, but also inside any <a href="/en-US/docs/CSS/At-rule#Conditional_Group_Rules" title="CSS/At-rule#Conditional_Group_Rules">CSS conditional-group at-rule</a>.</p>
<p>{{seeCompatTable}}</p>
<h2 id="語法">語法</h2>
<pre class="syntaxbox">@font-face {
[font-family: <family-name>;]?
[src: [ <uri> [format(<string>#)]? | <font-face-name> ]#;]?
[unicode-range: <urange>#;]?
[font-variant: <font-variant>;]?
[font-feature-settings: normal|<feature-tag-value>#;]?
[font-stretch: <font-stretch>;]?
[font-weight: <weight>];
[font-style: <style>];
}
</pre>
<h3 id="參數值">參數值</h3>
<dl>
<dt><code><family-name></code></dt>
<dd>Specifies a font name that will be used as font face value for font properties.</dd>
<dt><code><uri></code></dt>
<dd>URL for the remote font file location, or the name of a font on the user's computer in the form <code>local("Font Name")</code>.</dd>
<dt><code><font-variant></code></dt>
<dd>A {{cssxref("font-variant")}} value.</dd>
<dt><code><font-stretch></code></dt>
<dd>A {{cssxref("font-stretch")}} value.</dd>
<dt><code><weight></code></dt>
<dd>A <a href="/en-US/docs/CSS/font-weight" title="CSS/font-weight">font weight</a> value.</dd>
<dt><code><style></code></dt>
<dd>A <a href="/en-US/docs/CSS/font-style" title="CSS/font-style">font style</a> value.</dd>
</dl>
<p>You can specify a font on the user's local computer by name using the <code>local()</code> syntax. If that font isn't found, other sources will be tried until one is found.</p>
<h2 id="範例">範例</h2>
<p>這個範例指定一個可供下載的字型,並套用至 document 的整個 body。</p>
<p><a href="/@api/deki/files/2935/=webfont-sample.html" title="/@api/deki/files/2935/=webfont-sample.html">檢視線上範例</a></p>
<pre><html>
<head>
<title>Web Font Sample</title>
<style type="text/css" media="screen, print">
@font-face {
font-family: "Bitstream Vera Serif Bold";
src: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");
}
body { font-family: "Bitstream Vera Serif Bold", serif }
</style>
</head>
<body>
This is Bitstream Vera Serif Bold.
</body>
</html>
</pre>
<p>這個範例會套用使用者本地的 "Helvetica Neue Bold" 字型,只有當使用者未安裝該字型(兩種名稱都試過了),才會下載 "MgOpenModernaBold.ttf" 字型:</p>
<pre class="brush: css">@font-face {
font-family: MyHelvetica;
src: local("Helvetica Neue Bold"),
local("HelveticaNeue-Bold"),
url(MgOpenModernaBold.ttf);
font-weight: bold;
}
</pre>
<h2 id="注意事項">注意事項</h2>
<ul>
<li>In Gecko, web fonts are subject to the same domain restriction (font files must be on the same domain as the page using them), unless <a href="/en-US/docs/HTTP_access_control" title="HTTP access control">HTTP access controls</a> are used to relax this restriction.</li>
<li>
<div class="note"><strong>Note:</strong> Because there are no defined MIME types for TrueType, OpenType, and Web Open File Format (WOFF) fonts, the MIME type of the file specified is not considered.</div>
</li>
<li>When Gecko displays a page that uses web fonts, it initially displays text using the best CSS fallback font available on the user's computer while it waits for the web font to finish downloading. As each web font finishes downloading, Gecko updates the text that uses that font. This allows the user to read the text on the page more quickly.</li>
</ul>
<h2 id="規格文件">規格文件</h2>
<table class="standard-table">
<thead>
<tr>
<th scope="col">規格文件</th>
<th scope="col">狀態</th>
<th scope="col">註解</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{SpecName('WOFF1.0', '', 'WOFF font format')}}</td>
<td>{{Spec2('WOFF1.0')}}</td>
<td>字型格式規格文件</td>
</tr>
<tr>
<td>{{SpecName('CSS3 Fonts', '#font-face-rule', '@font-face')}}</td>
<td>{{Spec2('CSS3 Fonts')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>功能特色</th>
<th>Firefox (Gecko)</th>
<th>Chrome</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>基本支援</td>
<td>{{CompatGeckoDesktop("1.9.1")}}</td>
<td>4.0</td>
<td>4.0</td>
<td>10.0</td>
<td>3.1</td>
</tr>
<tr>
<td><a href="/en-US/docs/WOFF" title="About_WOFF">WOFF</a></td>
<td>{{CompatGeckoDesktop("1.9.1")}}</td>
<td>6.0</td>
<td>9.0</td>
<td>11.10</td>
<td>5.1</td>
</tr>
<tr>
<td>SVG 字型</td>
<td>{{CompatNo}}<br>
{{unimplemented_inline(119490)}}</td>
<td>有</td>
<td>{{CompatNo}}</td>
<td>有</td>
<td>有</td>
</tr>
<tr>
<td><code>unicode-range</code></td>
<td>
<p>yes <span style="line-height: 1.572;">({{bug(443976)}})</span></p>
</td>
<td>有</td>
<td>9.0</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>功能特色</th>
<th>Android</th>
<th>Firefox 行動版 (Gecko)</th>
<th>IE 行動版</th>
<th>Opera Mini</th>
<th>Opera 行動版</th>
<th>Safari 行動版</th>
</tr>
<tr>
<td>基本支援</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoMobile("1.9.1")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}</td>
<td>10.0</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td>WOFF</td>
<td>{{CompatNo}}</td>
<td>{{CompatGeckoMobile("5.0")}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}</td>
<td>11.0</td>
<td>{{CompatNo}}</td>
</tr>
<tr>
<td>SVG 字型</td>
<td>{{CompatNo}}</td>
<td>{{CompatNo}}<br>
{{unimplemented_inline(119490)}}</td>
<td>{{CompatUnknown}}</td>
<td>{{CompatNo}}</td>
<td>10.0</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
<tr>
<td><code>unicode-range</code></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<h3 id="注意事項_2">注意事項</h3>
<ul>
<li>Support of the Embedded OpenType font format is not included in the compatibility table because it is a proprietary feature. Prior to IE 9.0, IE supported only this format.</li>
<li>TrueType and OpenType are not included because they are superseded by WOFF.</li>
</ul>
<h2 id="詳見">詳見</h2>
<ul>
<li><a href="/en-US/docs/WOFF" title="About WOFF">About WOFF</a></li>
<li><a class="external" href="http://www.fontsquirrel.com/fontface/generator">FontSquirrel @font-face generator</a></li>
<li><a class="external" href="http://hacks.mozilla.org/2009/06/beautiful-fonts-with-font-face/">Beautiful fonts with @font-face</a></li>
<li><a class="external" href="http://openfontlibrary.org/" title="http://openfontlibrary.org/">Open Font Library</a></li>
<li><a class="external" href="http://msdn.microsoft.com/en-us/library/ms530757(VS.85).aspx">Microsoft Developer Network (MSDN) @font-face reference</a></li>
<li><a class="external" href="http://caniuse.com/woff">When can I use WOFF?</a></li>
<li><a class="external" href="http://caniuse.com/svg-fonts">When can I use SVG Fonts?</a></li>
</ul>
|