Skip to content

Outline Color 轮廓颜色

控制元素轮廓颜色的实用工具。

ClassProperties

基本用法

设置轮廓颜色

使用 outline-{color} 实用程序来更改元素轮廓的颜色。

outline-blue-500

outline-cyan-500

outline-pink-500

html
<button class="outline outline-offset-2 outline-blue-500 ...">Button A</button>
<button class="outline outline-offset-2 outline-cyan-500 ...">Button B</button>
<button class="outline outline-offset-2 outline-pink-500 ...">Button C</button>

改变不透明度

使用颜色不透明度修饰符控制元素轮廓颜色的不透明度。

outline-blue-500/50

html
<button class="outline-2 outline-blue-500/50 ...">Save Changes</button>

您可以使用您的不透明度比例中定义的任何值,或者如果需要偏离设计令牌,也可以使用任意值。

html
<button class="outline-4 outline-pink-400/[.55] ..."></button>

有条件地应用

悬停、焦点和其他状态

Tailwind 允许您使用变体修饰符在不同状态下有条件地应用实用程序类。例如,使用 hover:outline-blue-400 只在悬停时应用 outline-blue-400 实用程序。

html
<button class="outline hover:outline-blue-400">
	<!-- ... -->
</button>

有关所有可用状态修饰符的完整列表,请查看悬停、焦点和其他状态文档。

断点和媒体查询

您还可以使用变体修饰符来针对响应式断点、深色模式、prefers-reduced-motion 等媒体查询进行定位。例如,使用 md:outline-blue-400 仅在中等屏幕尺寸及以上应用 outline-blue-400 实用程序。

html
<button class="outline md:outline-blue-400">
	<!-- ... -->
</button>

要了解更多信息,请查看有关响应式设计深色模式其他媒体查询修饰符的文档。

使用自定义值

定制您的主题

默认情况下,Tailwind 将整个默认颜色调色板作为轮廓颜色可用。您可以通过编辑您的 tailwind.config.js 文件中的 theme.colorstheme.extend.colors 来自定义您的调色板。

js
module.exports = {
  theme: {
    extend: {
      colors: {						
        'regal-blue': '#243c5a',	
      },							
    }
  }
}

或者,您可以通过编辑 tailwind.config.js 文件中的 theme.outlineColortheme.extend.outlineColor 来自定义您的轮廓颜色。

有关自定义默认主题的更多信息,请参阅主题自定义文档。

任意值

如果您需要使用一个与主题无关的 divide-{color} 值,可以使用方括号来根据任意值动态生成属性。

html
<button class="outline-[#243c5a]">
	<!-- ... -->
</button>

有关任意值支持的更多信息,请参阅任意值文档。

Released under the MIT License.