Tailwind CSS 占位文本颜色

2022-08-08 10:02 更新

占位文本颜色

用于控制占位文本颜色的功能类。

Class
Properties
Preview 
placeholder-transparent::placeholder color: transparent;
Aa
placeholder-current::placeholder color: currentColor;
Aa
placeholder-black::placeholder --tw-placeholder-opacity: 1; color: rgba(0, 0, 0, var(--tw-placeholder-opacity));
Aa
placeholder-white::placeholder --tw-placeholder-opacity: 1; color: rgba(255, 255, 255, var(--tw-placeholder-opacity));
Aa
placeholder-gray-50::placeholder --tw-placeholder-opacity: 1; color: rgba(249, 250, 251, var(--tw-placeholder-opacity));
Aa
placeholder-gray-100::placeholder --tw-placeholder-opacity: 1; color: rgba(243, 244, 246, var(--tw-placeholder-opacity));
Aa
placeholder-gray-200::placeholder --tw-placeholder-opacity: 1; color: rgba(229, 231, 235, var(--tw-placeholder-opacity));
Aa
placeholder-gray-300::placeholder --tw-placeholder-opacity: 1; color: rgba(209, 213, 219, var(--tw-placeholder-opacity));
Aa
placeholder-gray-400::placeholder --tw-placeholder-opacity: 1; color: rgba(156, 163, 175, var(--tw-placeholder-opacity));
Aa
placeholder-gray-500::placeholder --tw-placeholder-opacity: 1; color: rgba(107, 114, 128, var(--tw-placeholder-opacity));
Aa
placeholder-gray-600::placeholder --tw-placeholder-opacity: 1; color: rgba(75, 85, 99, var(--tw-placeholder-opacity));
Aa
placeholder-gray-700::placeholder --tw-placeholder-opacity: 1; color: rgba(55, 65, 81, var(--tw-placeholder-opacity));
Aa
placeholder-gray-800::placeholder --tw-placeholder-opacity: 1; color: rgba(31, 41, 55, var(--tw-placeholder-opacity));
Aa
placeholder-gray-900::placeholder --tw-placeholder-opacity: 1; color: rgba(17, 24, 39, var(--tw-placeholder-opacity));
Aa
placeholder-red-50::placeholder --tw-placeholder-opacity: 1; color: rgba(254, 242, 242, var(--tw-placeholder-opacity));
Aa
placeholder-red-100::placeholder --tw-placeholder-opacity: 1; color: rgba(254, 226, 226, var(--tw-placeholder-opacity));
Aa
placeholder-red-200::placeholder --tw-placeholder-opacity: 1; color: rgba(254, 202, 202, var(--tw-placeholder-opacity));
Aa
placeholder-red-300::placeholder --tw-placeholder-opacity: 1; color: rgba(252, 165, 165, var(--tw-placeholder-opacity));
Aa
placeholder-red-400::placeholder --tw-placeholder-opacity: 1; color: rgba(248, 113, 113, var(--tw-placeholder-opacity));
Aa
placeholder-red-500::placeholder --tw-placeholder-opacity: 1; color: rgba(239, 68, 68, var(--tw-placeholder-opacity));
Aa
placeholder-red-600::placeholder --tw-placeholder-opacity: 1; color: rgba(220, 38, 38, var(--tw-placeholder-opacity));
Aa
placeholder-red-700::placeholder --tw-placeholder-opacity: 1; color: rgba(185, 28, 28, var(--tw-placeholder-opacity));
Aa
placeholder-red-800::placeholder --tw-placeholder-opacity: 1; color: rgba(153, 27, 27, var(--tw-placeholder-opacity));
Aa
placeholder-red-900::placeholder --tw-placeholder-opacity: 1; color: rgba(127, 29, 29, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-50::placeholder --tw-placeholder-opacity: 1; color: rgba(255, 251, 235, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-100::placeholder --tw-placeholder-opacity: 1; color: rgba(254, 243, 199, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-200::placeholder --tw-placeholder-opacity: 1; color: rgba(253, 230, 138, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-300::placeholder --tw-placeholder-opacity: 1; color: rgba(252, 211, 77, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-400::placeholder --tw-placeholder-opacity: 1; color: rgba(251, 191, 36, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-500::placeholder --tw-placeholder-opacity: 1; color: rgba(245, 158, 11, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-600::placeholder --tw-placeholder-opacity: 1; color: rgba(217, 119, 6, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-700::placeholder --tw-placeholder-opacity: 1; color: rgba(180, 83, 9, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-800::placeholder --tw-placeholder-opacity: 1; color: rgba(146, 64, 14, var(--tw-placeholder-opacity));
Aa
placeholder-yellow-900::placeholder --tw-placeholder-opacity: 1; color: rgba(120, 53, 15, var(--tw-placeholder-opacity));
Aa
placeholder-green-50::placeholder --tw-placeholder-opacity: 1; color: rgba(236, 253, 245, var(--tw-placeholder-opacity));
Aa
placeholder-green-100::placeholder --tw-placeholder-opacity: 1; color: rgba(209, 250, 229, var(--tw-placeholder-opacity));
Aa
placeholder-green-200::placeholder --tw-placeholder-opacity: 1; color: rgba(167, 243, 208, var(--tw-placeholder-opacity));
Aa
placeholder-green-300::placeholder --tw-placeholder-opacity: 1; color: rgba(110, 231, 183, var(--tw-placeholder-opacity));
Aa
placeholder-green-400::placeholder --tw-placeholder-opacity: 1; color: rgba(52, 211, 153, var(--tw-placeholder-opacity));
Aa
placeholder-green-500::placeholder --tw-placeholder-opacity: 1; color: rgba(16, 185, 129, var(--tw-placeholder-opacity));
Aa
placeholder-green-600::placeholder --tw-placeholder-opacity: 1; color: rgba(5, 150, 105, var(--tw-placeholder-opacity));
Aa
placeholder-green-700::placeholder --tw-placeholder-opacity: 1; color: rgba(4, 120, 87, var(--tw-placeholder-opacity));
Aa
placeholder-green-800::placeholder --tw-placeholder-opacity: 1; color: rgba(6, 95, 70, var(--tw-placeholder-opacity));
Aa
placeholder-green-900::placeholder --tw-placeholder-opacity: 1; color: rgba(6, 78, 59, var(--tw-placeholder-opacity));
Aa
placeholder-blue-50::placeholder --tw-placeholder-opacity: 1; color: rgba(239, 246, 255, var(--tw-placeholder-opacity));
Aa
placeholder-blue-100::placeholder --tw-placeholder-opacity: 1; color: rgba(219, 234, 254, var(--tw-placeholder-opacity));
Aa
placeholder-blue-200::placeholder --tw-placeholder-opacity: 1; color: rgba(191, 219, 254, var(--tw-placeholder-opacity));
Aa
placeholder-blue-300::placeholder --tw-placeholder-opacity: 1; color: rgba(147, 197, 253, var(--tw-placeholder-opacity));
Aa
placeholder-blue-400::placeholder --tw-placeholder-opacity: 1; color: rgba(96, 165, 250, var(--tw-placeholder-opacity));
Aa
placeholder-blue-500::placeholder --tw-placeholder-opacity: 1; color: rgba(59, 130, 246, var(--tw-placeholder-opacity));
Aa
placeholder-blue-600::placeholder --tw-placeholder-opacity: 1; color: rgba(37, 99, 235, var(--tw-placeholder-opacity));
Aa
placeholder-blue-700::placeholder --tw-placeholder-opacity: 1; color: rgba(29, 78, 216, var(--tw-placeholder-opacity));
Aa
placeholder-blue-800::placeholder --tw-placeholder-opacity: 1; color: rgba(30, 64, 175, var(--tw-placeholder-opacity));
Aa
placeholder-blue-900::placeholder --tw-placeholder-opacity: 1; color: rgba(30, 58, 138, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-50::placeholder --tw-placeholder-opacity: 1; color: rgba(238, 242, 255, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-100::placeholder --tw-placeholder-opacity: 1; color: rgba(224, 231, 255, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-200::placeholder --tw-placeholder-opacity: 1; color: rgba(199, 210, 254, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-300::placeholder --tw-placeholder-opacity: 1; color: rgba(165, 180, 252, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-400::placeholder --tw-placeholder-opacity: 1; color: rgba(129, 140, 248, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-500::placeholder --tw-placeholder-opacity: 1; color: rgba(99, 102, 241, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-600::placeholder --tw-placeholder-opacity: 1; color: rgba(79, 70, 229, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-700::placeholder --tw-placeholder-opacity: 1; color: rgba(67, 56, 202, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-800::placeholder --tw-placeholder-opacity: 1; color: rgba(55, 48, 163, var(--tw-placeholder-opacity));
Aa
placeholder-indigo-900::placeholder --tw-placeholder-opacity: 1; color: rgba(49, 46, 129, var(--tw-placeholder-opacity));
Aa
placeholder-purple-50::placeholder --tw-placeholder-opacity: 1; color: rgba(245, 243, 255, var(--tw-placeholder-opacity));
Aa
placeholder-purple-100::placeholder --tw-placeholder-opacity: 1; color: rgba(237, 233, 254, var(--tw-placeholder-opacity));
Aa
placeholder-purple-200::placeholder --tw-placeholder-opacity: 1; color: rgba(221, 214, 254, var(--tw-placeholder-opacity));
Aa
placeholder-purple-300::placeholder --tw-placeholder-opacity: 1; color: rgba(196, 181, 253, var(--tw-placeholder-opacity));
Aa
placeholder-purple-400::placeholder --tw-placeholder-opacity: 1; color: rgba(167, 139, 250, var(--tw-placeholder-opacity));
Aa
placeholder-purple-500::placeholder --tw-placeholder-opacity: 1; color: rgba(139, 92, 246, var(--tw-placeholder-opacity));
Aa
placeholder-purple-600::placeholder --tw-placeholder-opacity: 1; color: rgba(124, 58, 237, var(--tw-placeholder-opacity));
Aa
placeholder-purple-700::placeholder --tw-placeholder-opacity: 1; color: rgba(109, 40, 217, var(--tw-placeholder-opacity));
Aa
placeholder-purple-800::placeholder --tw-placeholder-opacity: 1; color: rgba(91, 33, 182, var(--tw-placeholder-opacity));
Aa
placeholder-purple-900::placeholder --tw-placeholder-opacity: 1; color: rgba(76, 29, 149, var(--tw-placeholder-opacity));
Aa
placeholder-pink-50::placeholder --tw-placeholder-opacity: 1; color: rgba(253, 242, 248, var(--tw-placeholder-opacity));
Aa
placeholder-pink-100::placeholder --tw-placeholder-opacity: 1; color: rgba(252, 231, 243, var(--tw-placeholder-opacity));
Aa
placeholder-pink-200::placeholder --tw-placeholder-opacity: 1; color: rgba(251, 207, 232, var(--tw-placeholder-opacity));
Aa
placeholder-pink-300::placeholder --tw-placeholder-opacity: 1; color: rgba(249, 168, 212, var(--tw-placeholder-opacity));
Aa
placeholder-pink-400::placeholder --tw-placeholder-opacity: 1; color: rgba(244, 114, 182, var(--tw-placeholder-opacity));
Aa
placeholder-pink-500::placeholder --tw-placeholder-opacity: 1; color: rgba(236, 72, 153, var(--tw-placeholder-opacity));
Aa
placeholder-pink-600::placeholder --tw-placeholder-opacity: 1; color: rgba(219, 39, 119, var(--tw-placeholder-opacity));
Aa
placeholder-pink-700::placeholder --tw-placeholder-opacity: 1; color: rgba(190, 24, 93, var(--tw-placeholder-opacity));
Aa
placeholder-pink-800::placeholder --tw-placeholder-opacity: 1; color: rgba(157, 23, 77, var(--tw-placeholder-opacity));
Aa
placeholder-pink-900::placeholder --tw-placeholder-opacity: 1; color: rgba(131, 24, 67, var(--tw-placeholder-opacity));
Aa

使用方法

使用 ​placeholder-{color}​ 功能类控制元素占位文本的颜色。


<input class="placeholder-gray-500 ..." placeholder="jane@example.com">
<input class="placeholder-red-300 ..." placeholder="jane@example.com">

改变不透明度

使用 ​placeholder-opacity-{amount}​ 功能类控制元素的占位文本颜色的不透明度。


<input class="placeholder-gray-500 placeholder-opacity-100 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-75 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-50 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-25 ..." placeholder="jane@example.com">
<input class="placeholder-gray-500 placeholder-opacity-0 ..." placeholder="jane@example.com">

响应式

要在特定的断点处控制输入框占位文本的颜色,请在任何现有的占位文本颜色功能类前添加 ​{screen}:​ 前缀。例如,使用 ​md:placeholder-green-500​ 来仅在中等大小及以上的屏幕应用 ​placeholder-green-500​ 功能类。

<input class="placeholder-gray-500 md:placeholder-green-500" placeholder="jane@example.com">

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

焦点

要控制获得焦点时元素的占位文本颜色,请在任何现有的占位文本颜色功能类前添加 ​focus:​ 前缀。例如,使用 ​focus:placeholder-blue-600​ 在获得焦点时应用 ​placeholder-blue-600​ 功能类。


<input class="placeholder-gray-600 focus:placeholder-gray-400 ..." placeholder="jane@example.com">

通过在 ​focus:​ 前缀前添加响应式 ​{screen}:​ 前缀,focus 功能类也可以与 responsive 功能类相结合。

<input class="... md:placeholder-gray-900 md:focus:placeholder-red-600 ...">

自定义

占位符文本颜色

默认情况下,Tailwind 使整个默认调色板可用作占位符颜色。

您可以通过编辑 ​tailwind.config.js​ 文件中的 ​theme.colors​ 来 自定义您的调色板,或者在 ​theme.textColor​ 部分只自定义您的占位文本颜色。

  // tailwind.config.js
  module.exports = {
    theme: {
     placeholderColor: theme => theme('colors'),
     placeholderColor: {
       'primary': '#3490dc',
       'secondary': '#ffed4a',
       'danger': '#e3342f',
     }
    }
  }

变体

默认情况下, 针对 placeholder color 功能类,只生成 responsive, dark mode (if enabled) and focus 变体。

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

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

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

禁用

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

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


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号