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

Ring Color

Utilities for setting the color of outline rings.

Default class reference

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

Usage

Use the ring-{color} utilities to set the color of an outline ring.

<button class="... ring-4 ring-indigo-300">
  Button
</button>

Changing opacity

You can control the opacity of rings using the ring-opacity-{amount} utilities:

<button class="... ring-4 ring-yellow-500 ring-opacity-50">
  Button
</button>

For more information, see the ringOpacity documentation.


Responsive

To control the ring color at a specific breakpoint, add a {screen}: prefix to any existing ring color utility. For example, use md:ring-blue-500 to apply the ring-blue-500 utility at only medium screen sizes and above.

<button class="ring-2 ring-blue-300 md:ring-blue-500">
  <!-- ... -->
</button>

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


Customizing

You can customize which ring color utilities are generated by customizing your color palette using the colors key in the theme section of your tailwind.config.js file:

// tailwind.config.js
const colors = require('tailwindcss/colors')

module.exports = {
  theme: {
    colors: {
      gray: colors.blueGray,
      indigo: colors.indigo,
      red: colors.rose,
      yellow: colors.yellow,
    }
  }
}

If you’d like to customize only the ring color utilities without affecting your global color palette, use the ringColor key instead:

// tailwind.config.js
const colors = require('tailwindcss/colors')

module.exports = {
  theme: {
    ringColor: {
      white: colors.white,
      pink: colors.fuchsia,
    }
  }
}

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

Variants

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

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

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

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

Disabling

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

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