font-synthesis-style
font-synthesis-style CSS 屬性允許您指定當字型家族中缺少斜體字形時,瀏覽器是否可以合成斜體字形。
通常,使用簡寫屬性 font-synthesis 來控制所有字型合成值會更方便。
語法
css
/* Keyword values */
font-synthesis-style: auto;
font-synthesis-style: none;
font-synthesis-style: oblique-only;
/* Global values */
font-synthesis-style: inherit;
font-synthesis-style: initial;
font-synthesis-style: revert;
font-synthesis-style: revert-layer;
font-synthesis-style: unset;
值
auto-
表示如果需要,瀏覽器可以合成缺失的斜體字形。
none-
表示不允許瀏覽器合成缺失的斜體字形。
僅斜體(oblique-only)-
與
auto相同,但如果設定了font-style: italic則不會發生字型合成。
正式定義
| 初始值 | auto |
|---|---|
| 應用於 | 所有元素和文字。它也適用於 ::first-letter 和 ::first-line。 |
| 繼承性 | 是 |
| 計算值 | 同指定值 |
| 動畫型別 | 離散 |
正式語法
font-synthesis-style =
auto |
none |
oblique-only
示例
停用斜體字形合成
此示例展示了在 Montserrat 字型中關閉瀏覽器對斜體字形的合成。
HTML
html
<p class="english">
This is the default <em>oblique typeface</em> and
<strong>bold typeface</strong>.
</p>
<p class="english no-syn">
The <em>oblique typeface</em> is turned off here but not the
<strong>bold typeface</strong>.
</p>
CSS
css
@import "https://fonts.googleapis.com/css2?family=Montserrat&display=swap";
.english {
font-family: "Montserrat", sans-serif;
}
.no-syn {
font-synthesis-style: none;
}
結果
font-synthesis-style 值比較
此示例使用斜體和傾斜樣式文字比較所有 font-synthesis-style 值。
HTML
html
<div class="fss-none">
<h2>font-synthesis-style: none</h2>
<p class="oblique">This text is set to <code>oblique</code></p>
<p class="italic">This text is set to <code>italic</code></p>
</div>
<div class="fss-auto">
<h2>font-synthesis-style: auto</h2>
<p class="oblique">This text is set to <code>oblique</code></p>
<p class="italic">This text is set to <code>italic</code></p>
</div>
<div class="fss-oblique-only">
<h2>font-synthesis-style: oblique-only</h2>
<p class="oblique">This text is set to <code>oblique</code></p>
<p class="italic">This text is set to <code>italic</code></p>
</div>
CSS
css
/* Specify style of the font synthesis */
.fss-none {
font-synthesis-style: none;
}
.fss-auto {
font-synthesis-style: auto;
}
.fss-oblique-only {
font-synthesis-style: oblique-only;
}
/* Set font styles */
.oblique {
font-style: oblique;
}
.italic {
font-style: italic;
}
/* Styles for the demonstration */
.oblique::after {
content: " (font-style: oblique)";
font-size: 0.8rem;
vertical-align: sub;
}
.italic::after {
content: " (font-style: italic)";
font-size: 0.8rem;
vertical-align: sub;
}
結果
規範
| 規範 |
|---|
| CSS 字型模組第 4 級 # font-synthesis-style |
瀏覽器相容性
載入中…