font-synthesis-weight

Baseline 已廣泛支援

此功能已成熟,並可在許多裝置和瀏覽器版本上執行。自 2023 年 3 月以來,它已在各種瀏覽器中可用。

font-synthesis-weight CSS 屬性允許你指定當字型家族中缺少粗體字形時,瀏覽器是否可以合成粗體字形。

通常,使用簡寫屬性 font-synthesis 來控制所有字型合成值會更方便。

語法

css
/* Keyword values */
font-synthesis-weight: auto;
font-synthesis-weight: none;

/* Global values */
font-synthesis-weight: inherit;
font-synthesis-weight: initial;
font-synthesis-weight: revert;
font-synthesis-weight: revert-layer;
font-synthesis-weight: unset;

auto

表示如果需要,瀏覽器可以合成缺失的粗體字形。

none

表示不允許瀏覽器合成缺失的粗體字形。

正式定義

初始值auto
應用於所有元素和文字。它也適用於 ::first-letter::first-line
繼承性
計算值同指定值
動畫型別離散

正式語法

font-synthesis-weight = 
auto |
none

示例

停用粗體字形合成

此示例展示了在 Montserrat 字型中關閉瀏覽器合成粗體字形。

HTML

html
<p class="english">
  This is the default <strong>bold typeface</strong> and
  <em>oblique typeface</em>.
</p>

<p class="english no-syn">
  The <strong>bold typeface</strong> is turned off here but not the
  <em>oblique typeface</em>.
</p>

CSS

css
@import "https://fonts.googleapis.com/css2?family=Montserrat&display=swap";

.english {
  font-family: "Montserrat", sans-serif;
}
.no-syn {
  font-synthesis-weight: none;
}

結果

規範

規範
CSS 字型模組第 4 級
# font-synthesis-weight

瀏覽器相容性

另見