font-stretch
用于选择字面宽度的工具类。
快速参考
| 类 | 属性 |
|---|---|
font-stretch-ultra-condensed | font-stretch: ultra-condensed; /* 50% */ |
font-stretch-extra-condensed | font-stretch: extra-condensed; /* 62.5% */ |
font-stretch-condensed | font-stretch: condensed; /* 75% */ |
font-stretch-semi-condensed | font-stretch: semi-condensed; /* 87.5% */ |
font-stretch-normal | font-stretch: normal; /* 100% */ |
font-stretch-semi-expanded | font-stretch: semi-expanded; /* 112.5% */ |
font-stretch-expanded | font-stretch: expanded; /* 125% */ |
font-stretch-extra-expanded | font-stretch: extra-expanded; /* 150% */ |
font-stretch-ultra-expanded | font-stretch: ultra-expanded; /* 200% */ |
font-stretch-<percentage> | font-stretch: <percentage>; |
font-stretch-(<custom-property>) | font-stretch: var(<custom-property>); |
font-stretch-[<value>] | font-stretch: <value>; |
示例
基础示例
使用 font-stretch-condensed 和 font-stretch-expanded 等工具类来设置字面宽度:
font-stretch-extra-condensed
The quick brown fox jumps over the lazy dog.
font-stretch-condensed
The quick brown fox jumps over the lazy dog.
font-stretch-normal
The quick brown fox jumps over the lazy dog.
font-stretch-expanded
font-stretch-extra-expanded
html
<!-- [!code classes:font-stretch-extra-condensed,font-stretch-condensed,font-stretch-normal,font-stretch-expanded,font-stretch-extra-expanded] -->
<p class="font-stretch-extra-condensed">The quick brown fox...</p>
<p class="font-stretch-condensed">The quick brown fox...</p>
<p class="font-stretch-normal">The quick brown fox...</p>
<p class="font-stretch-expanded">The quick brown fox...</p>
<p class="font-stretch-extra-expanded">The quick brown fox...</p>这仅适用于提供多种宽度变体的字体,否则浏览器会选择最接近的匹配。
使用百分比
使用 font-stretch-50% 和 font-stretch-125% 等 font-stretch-<percentage> 工具类,以百分比设置字面宽度:
font-stretch-50%
The quick brown fox jumps over the lazy dog.
font-stretch-100%
The quick brown fox jumps over the lazy dog.
font-stretch-150%
The quick brown fox jumps over the lazy dog.
html
<!-- [!code classes:font-stretch-50%,font-stretch-100%,font-stretch-150%] -->
<p class="font-stretch-50%">The quick brown fox...</p>
<p class="font-stretch-100%">The quick brown fox...</p>
<p class="font-stretch-150%">The quick brown fox...</p>使用自定义值
使用 font-stretch-[<value>] 等工具类,可根据完全自定义的值设置字体宽度:
html
<p class="font-stretch-[66.66%] ...">
Lorem ipsum dolor sit amet...
</p>对于 CSS 变量,也可以使用 font-stretch-(<custom-property>) 语法:
html
<p class="font-stretch-(--my-font-width) ...">
Lorem ipsum dolor sit amet...
</p>这只是 font-stretch-[var(<custom-property>)] 的简写,会自动为你加上 var() 函数。
响应式设计
使用 md: 等断点变体前缀,即可让 font-stretch 工具类仅在中等及以上屏幕尺寸下生效:
html
<div class="font-stretch-normal md:font-stretch-expanded ...">
<!-- ... -->
</div>在变体文档中了解更多关于使用变体的信息。