你正在瀏覽的是 Tailwind CSS v2. 的技術文件
Tailwind CSS 的 GitHub

Text Opacity

Utilities for controlling the opacity of an element's text color.

Default class reference

Class
屬性
text-opacity-0--tw-text-opacity: 0;
text-opacity-5--tw-text-opacity: 0.05;
text-opacity-10--tw-text-opacity: 0.1;
text-opacity-20--tw-text-opacity: 0.2;
text-opacity-25--tw-text-opacity: 0.25;
text-opacity-30--tw-text-opacity: 0.3;
text-opacity-40--tw-text-opacity: 0.4;
text-opacity-50--tw-text-opacity: 0.5;
text-opacity-60--tw-text-opacity: 0.6;
text-opacity-70--tw-text-opacity: 0.7;
text-opacity-75--tw-text-opacity: 0.75;
text-opacity-80--tw-text-opacity: 0.8;
text-opacity-90--tw-text-opacity: 0.9;
text-opacity-95--tw-text-opacity: 0.95;
text-opacity-100--tw-text-opacity: 1;

Usage

Control the opacity of an element’s text color using the text-opacity-{amount} utilities.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

The quick brown fox jumps over the lazy dog.

<p class="text-purple-700 text-opacity-100 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-75 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-50 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-25 ...">The quick brown fox ...</p>
<p class="text-purple-700 text-opacity-0 ...">The quick brown fox ...</p>

Note that because these utilities are implemented using CSS custom properties, a .text-{color} utility must be present on the same element for them to work.

Don't try to use text opacity utilities on an inherited text color

<div class="text-black">
  <div class="text-opacity-50">...</div>
</div>

Do make sure to add a text color utility to the same element explicitly

<div class="text-black">
  <div class="text-black text-opacity-50">...</div>
</div>

Responsive

To control an element’s text color opacity at a specific breakpoint, add a {screen}: prefix to any existing text color opacity utility. For example, use md:text-opacity-50 to apply the text-opacity-50 utility at only medium screen sizes and above.

<div class="text-blue-500 text-opacity-75 md:text-opacity-50">
  <!-- ... -->
</div>

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

Customizing

To customize the opacity values for all opacity-related utilities at once, use the opacity section of your tailwind.config.js theme configuration:

  // tailwind.config.js
  module.exports = {
    theme: {
      extend: {
        opacity: {
+         '10': '0.1',
+         '20': '0.2',
+         '95': '0.95',
        }
      }
    }
  }

If you want to customize only the text opacity utilities, use the textOpacity section:

  // tailwind.config.js
  module.exports = {
    theme: {
      extend: {
        textOpacity: {
+         '10': '0.1',
+         '20': '0.2',
+         '95': '0.95',
        }
      }
    }
  }

Learn more about customizing the default theme in the theme customization documentation.

Variants

默認情況下, 只有 響應式、深色模式 (如果啟用)、group-hover、focus-within、hover 和 focus 的 text opacity 變化模式 (variants) 會產生。

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

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

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

Disabling

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

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