1. 字体
  2. text-wrap

字体

文本换行

用于控制元素内文本换行方式的工具类。

ClassStyles
text-wrap
text-wrap: wrap;
text-nowrap
text-wrap: nowrap;
text-balance
text-wrap: balance;
text-pretty
text-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>

响应式设计

Prefix a text-wrap utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

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

Learn more about using variants in the variants documentation.

Copyright © 2025 Tailwind Labs Inc.·Trademark Policy