阅读(3869) (0)

Tailwind CSS 文本转换

2022-07-25 17:03:08 更新

文本转换

用于控制文本转换的功能类。

Class
Properties
uppercase text-transform: uppercase;
lowercase text-transform: lowercase;
capitalize text-transform: capitalize;
normal-case text-transform: none;

Normal Case

使用 ​normal-case​ 功能类来保留原来的外壳,这通常用于在不同的断点处重置大写。


<p class="normal-case ...">The quick brown fox ...</p>

Uppercase

使用 ​uppercase ​功能类对文本进行大写转换。


<p class="uppercase ...">The quick brown fox ...</p>

Lowercase

使用 ​lowercase ​功能类对文本进行小写转换。


<p class="lowercase ...">The quick brown fox ...</p>

Capitalize

使用 ​capitalize ​功能类对文本进行首字母大写转换。


<p class="capitalize ...">The quick brown fox ...</p>

响应式

要在特定的断点处控制元素的文本转换,可在任何现有的文本转换功能类中添加 ​{screen}:​ 前缀。例如,使用 ​md:uppercase​ 来应用 ​uppercase ​功能类在中等大小的屏幕和更大的屏幕上。

<p class="capitalize md:uppercase ...">
  The quick brown fox jumps over the lazy dog.
</p>

关于 Tailwind 的响应式设计功能的更多信息,请查看响应式设计文档。

自定义

变体

默认情况下, 针对 text transformation 功能类,只生成 responsive 变体。

您可以通过修改您的 ​tailwind.config.js​ 文件中的 ​variants ​部分中的 ​textTransform ​属性来控制为 text transformation 功能生成哪些变体。

例如,这个配置也将生成 hover and focus 变体:

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
       textTransform: ['hover', 'focus'],
      }
    }
  }

设计

如果您不打算在您的项目中使用 text transformation 功能,您可以通过在配置文件的 ​corePlugins ​部分将 ​textTransform ​属性设置为 ​false ​来完全禁用它们:

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