「及時」模式:全新世代的 Tailwind CSS
Tailwind CSS on GitHub

Text Overflow

Utilities for controlling text overflow in an element.

Default class reference

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

Truncate

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

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiisitaquequodpraesentiumexplicaboincidunt? Dolores beatae nam at sed dolorum ratione dolorem nisi velit cum.

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

Overflow Ellipsis

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

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiisitaquequodpraesentiumexplicaboincidunt? Dolores beatae nam at sed dolorum ratione dolorem nisi velit cum.

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

Overflow Clip

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

Lorem ipsum dolor sit amet, consectetur adipisicing elit. Blanditiisitaquequodpraesentiumexplicaboincidunt? Dolores beatae nam at sed dolorum ratione dolorem nisi velit cum.

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

Responsive

To control the text overflow in an element only at a specific breakpoint, add a {screen}: prefix to any existing text overflow utility. For example, adding the class md:overflow-clip to an element would apply the overflow-clip utility at medium screen sizes and above.

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

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Customizing

Variants

默認情況下, 只有 響應式 的 text overflow 變化模式 (variants) 會產生。

tailwind.config.jsvariants 區塊中變更 textOverflow 屬性來決定有哪些變化模式會生成。

舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       textOverflow: ['responsive', 'hover'],
      }
    }
  }

Disabling

如果你不打算在專案中使用 text overflow 功能,可以在你的設定檔裡的 corePlugins 屬性中將 textOverflow 設定為 false 來停用功能:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     textOverflow: false,
    }
  }