Skip to content

Text Overflow 文本溢出

控制元素中文本溢出的实用工具。

ClassProperties

基本用法

Truncate 截断

使用 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.

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

Ellipsis 省略号

使用 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.

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

Clip 夹

使用 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.

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

有条件地应用

悬停、焦点和其他状态

Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:text-clip 只在悬停时应用 text-clip 实用程序。

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

有关所有可用状态修改器的完整列表,请查看悬停、焦点和其他状态文档。

断点和媒体查询

您还可以使用变体修饰符来针对响应式断点、深色模式、prefers-reduced-motion 等媒体查询进行定位。例如,使用 md:text-clip 仅在中等屏幕尺寸及以上应用 text-clip 实用程序。

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

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

Released under the MIT License.