1. 排版
  2. 文本溢出

Quick reference

Class
Properties
truncateoverflow: hidden; text-overflow: ellipsis; white-space: nowrap;
text-ellipsistext-overflow: ellipsis;
text-cliptext-overflow: clip;

基础用法

截断

使用 truncate 防止文本换行,并在必要时使用省略号 () 截断溢出的文本。

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>

省略号

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

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>

夹子

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

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>

详细了解, 请参考 Hover, Focus, & Other States 文档.

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗模式、首选减少运动等。例如, 使用 md:text-clip 来应用 text-clip 程序,适用于中等屏幕尺寸及以上。

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

进一步了解,请参考 响应式设计, 暗黑模式 媒体查询.