font-stretch
已棄用:此特性不再推薦。雖然某些瀏覽器可能仍然支援它,但它可能已經從相關的網路標準中刪除,可能正在刪除過程中,或者可能僅為相容性目的而保留。請避免使用它,如果可能,請更新現有程式碼;請參閱本頁底部的相容性表格以指導您的決策。請注意,此特性可能隨時停止工作。
注意:font-stretch 屬性現在已在規範中更名為 font-width。font-stretch 名稱已被保留作為 font-width 屬性的別名。新名稱 font-width 尚未被任何瀏覽器支援。
font-stretch CSS 屬性從字型中選擇正常、凝縮或擴充套件的字形。
試一試
font-stretch: condensed;
font-stretch: expanded;
font-stretch: ultra-expanded;
font-stretch: 50%;
font-stretch: 100%;
font-stretch: 150%;
<section class="default-example" id="default-example">
<p class="transition-all" id="example-element">
London. Michaelmas term lately over, and the Lord Chancellor sitting in
Lincoln's Inn Hall. Implacable November weather. As much mud in the streets
as if the waters had but newly retired from the face of the earth, and it
would not be wonderful to meet a Megalosaurus, forty feet long or so,
waddling like an elephantine lizard up Holborn Hill.
</p>
</section>
@font-face {
src: url("/shared-assets/fonts/LeagueMono-VF.ttf") format("truetype");
font-family: "League";
font-style: normal;
font-weight: normal;
font-stretch: 50% 200%; /* Required by Chrome - allow 50% to 200% */
}
section {
font-size: 1.2em;
font-family: "League", sans-serif;
}
語法
/* <font-stretch-css3> keyword values */
font-stretch: normal;
font-stretch: ultra-condensed;
font-stretch: extra-condensed;
font-stretch: condensed;
font-stretch: semi-condensed;
font-stretch: semi-expanded;
font-stretch: expanded;
font-stretch: extra-expanded;
font-stretch: ultra-expanded;
/* Percentage values */
font-stretch: 50%;
font-stretch: 100%;
font-stretch: 200%;
/* Global values */
font-stretch: inherit;
font-stretch: initial;
font-stretch: revert;
font-stretch: revert-layer;
font-stretch: unset;
此屬性可以指定為單個 <font-stretch-css3> 關鍵字值或單個<percentage> 值。
值
normal-
指定正常字型字形。
semi-condensed、condensed、extra-condensed、ultra-condensed-
指定比正常字形更凝縮的字型字形,其中
ultra-condensed是最凝縮的。 semi-expanded、expanded、extra-expanded、ultra-expanded-
指定比正常字形更擴充套件的字型字形,其中
ultra-expanded是最擴充套件的。 <percentage>-
一個介於 50% 和 200%(含)之間的
<percentage>值。此屬性不允許使用負值。
關鍵字到數字的對映
下表顯示了 <font-stretch-css3> 關鍵字值和數字百分比之間的對映
| 關鍵字 | 百分比 |
|---|---|
ultra-condensed |
50% |
extra-condensed |
62.5% |
condensed |
75% |
semi-condensed |
87.5% |
normal |
100% |
semi-expanded |
112.5% |
expanded |
125% |
extra-expanded |
150% |
ultra-expanded |
200% |
描述
一些字型家族提供額外的字形,其中字元比正常字形更窄(凝縮字形)或更寬(擴充套件字形)。
您可以使用 font-stretch 從此類字型中選擇凝縮或擴充套件的字形。如果您使用的字型不提供凝縮或擴充套件的字形,則此屬性無效。
字型字形選擇
為給定 font-stretch 值選擇的字形取決於所選字型支援的字形。如果字型未提供與給定值完全匹配的字形,則小於 100% 的值對映到較窄的字形,大於或等於 100% 的值對映到較寬的字形。
下表演示了在兩種不同字型上提供各種不同百分比的 font-stretch 值時的效果
- Anek Malayalam 是一種可變 Google 字型,支援 75% 到 125% 的寬度。此範圍之外的值會選擇最接近的匹配字型。
- Inconsolata 是一種可變字型,提供 50% 到 200% 的連續寬度範圍。
正式定義
| 初始值 | normal |
|---|---|
| 應用於 | 所有元素和文字。它也適用於 ::first-letter 和 ::first-line。 |
| 繼承性 | 是 |
| 計算值 | 同指定值 |
| 動畫型別 | 按計算值型別 |
正式語法
font-width =
normal |
<percentage [0,∞]> |
ultra-condensed |
extra-condensed |
condensed |
semi-condensed |
semi-expanded |
expanded |
extra-expanded |
ultra-expanded
示例
設定字型拉伸百分比
<p class="condensed">an elephantine lizard</p>
<p class="normal">an elephantine lizard</p>
<p class="expanded">an elephantine lizard</p>
@font-face {
src: url("https://mdn.github.io/shared-assets/fonts/LeagueMono-VF.ttf");
font-family: "LeagueMonoVariable";
font-style: normal;
font-stretch: 1% 500%; /* Required by Chrome */
}
p {
font:
1.5rem "LeagueMonoVariable",
sans-serif;
}
.condensed {
font-stretch: 50%;
}
.normal {
font-stretch: 100%;
}
.expanded {
font-stretch: 200%;
}
規範
| 規範 |
|---|
| CSS 字型模組第 4 級 # font-stretch-prop |
瀏覽器相容性
載入中…
另見
font-stylefont-weight- SVG
font-stretch屬性 - 學習:基礎文字和字型樣式
- CSS 字型模組