font-synthesis-style

Baseline 已广泛支持

此功能已成熟,并可在许多设备和浏览器版本上运行。自 2023 年 3 月以来,它已在各种浏览器中可用。

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

浏览器兼容性

另见