1. 排版
  2. 文本溢出

Quick reference

属性
truncateoverflow: hidden; text-overflow: ellipsis; white-space: nowrap;
text-ellipsistext-overflow: ellipsis;
text-cliptext-overflow: clip;

基本用法

¥Basic usage

截短

¥Truncate

使用 truncate 防止文本换行,并根据需要使用省略号 () 截断溢出的文本。

¥Use truncate to prevent text from wrapping and truncate overflowing text with an ellipsis () if needed.

The longest word in any of the major English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis.

<p class="truncate ...">...</p>

省略

¥Ellipsis

如果需要,使用 text-ellipsis 以省略号 () 截断溢出的文本。

¥Use text-ellipsis to truncate overflowing text with an ellipsis () if needed.

The longest word in any of the major English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis.

<p class="text-ellipsis overflow-hidden ...">...</p>

夹子

¥Clip

使用 text-clip 在内容区域的限制处截断文本。

¥Use text-clip to truncate the text at the limit of the content area.

The longest word in any of the major English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis, a word that refers to a lung disease contracted from the inhalation of very fine silica particles, specifically from a volcano; medically, it is the same as silicosis.

<p class="text-clip overflow-hidden ...">...</p>

有条件地应用

悬停、聚焦和其他状态

Tailwind 允许你使用变体修饰符在不同状态下有条件地应用工具类。例如,使用hover:text-clip 仅在 hover 时应用 text-clip 工具。

<p class="truncate hover:text-clip">
  <!-- ... -->
</p>

有关所有可用状态修饰符的完整列表,请查看悬停、聚焦、以及其他状态 文档。

断点和媒体查询

你还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗黑模式、首选减少运动等。例如,使用 md:text-clip 仅在中等屏幕尺寸及以上时应用 text-clip 工具。

<p class="truncate md:text-clip">
  <!-- ... -->
</p>

要了解更多信息,请查看有关 响应式设计暗黑模式、以及 其他媒体查询修饰符 的文档。