Lzh on GitHub

text-wrap

用于控制元素中文本如何换行的工具。

快速参考

类别样式
text-wraptext-wrap: wrap;
text-nowraptext-wrap: nowrap;
text-balancetext-wrap: balance;
text-prettytext-wrap: pretty;

示例

允许文本换行

使用 text-wrap 工具可以在文本的逻辑断点处将溢出的文本换行到多行:

Beloved Manhattan soup stand closes

New Yorkers are facing the winter chill with less warmth this year as the city's most revered soup stand unexpectedly shutters, following a series of events that have left the community puzzled.

<article class="text-wrap">
  <h3>Beloved Manhattan soup stand closes</h3>
  <p>New Yorkers are facing the winter chill...</p>
</article>

防止文本换行

使用 text-nowrap 工具可以防止文本换行,必要时允许其溢出:

Beloved Manhattan soup stand closes

New Yorkers are facing the winter chill with less warmth this year as the city's most revered soup stand unexpectedly shutters, following a series of events that have left the community puzzled.

<article class="text-nowrap">
  <h3>Beloved Manhattan soup stand closes</h3>
  <p>New Yorkers are facing the winter chill...</p>
</article>

平衡文本换行

使用 text-balance 工具可以将文本均匀分布在每一行中:

Beloved Manhattan soup stand closes

New Yorkers are facing the winter chill with less warmth this year as the city's most revered soup stand unexpectedly shutters, following a series of events that have left the community puzzled.

<article>
  <h3 class="text-balance">Beloved Manhattan soup stand closes</h3>
  <p>New Yorkers are facing the winter chill...</p>
</article>

出于性能原因,浏览器将文本平衡限制在大约 6 行或更少的块中,因此它最适合标题。

优化文本换行

使用 text-pretty 工具可以防止文本块末尾出现孤行(单独一行的单词):

Beloved Manhattan soup stand closes

New Yorkers are facing the winter chill with less warmth this year as the city's most revered soup stand unexpectedly shutters, following a series of events that have left the community puzzled.

<article>
  <h3 class="text-pretty">Beloved Manhattan soup stand closes</h3>
  <p>New Yorkers are facing the winter chill...</p>
</article>

响应式设计

text-wrap 工具前加上像 md: 这样的断点变体,以便只在中等屏幕尺寸及以上应用该工具:

<h1 class="text-pretty md:text-balance ...">
  </h1>

变体文档 中了解更多关于使用变体的信息。