Skip to content

Hue Rotate 色相旋转

将色相旋转滤镜应用到元素的实用工具。

ClassProperties

基本用法

旋转元素的色调

使用 hue-rotate-{amount} 实用程序来旋转元素的色调。

hue-rotate-15

hue-rotate-90

hue-rotate-180

-hue-rotate-60

html
<div class="hue-rotate-15 ...">
  <!-- ... -->
</div>
<div class="hue-rotate-90 ...">
  <!-- ... -->
</div>
<div class="hue-rotate-180 ...">
  <!-- ... -->
</div>
<div class="-hue-rotate-60 ...">
  <!-- ... -->
</div>

使用负值

要使用负的 hue-rotate 值,需要在类名前加上破折号,将其转换为负值。

html
<div class="-hue-rotate-60 ...">
  <!-- ... -->
</div>

移除滤镜

要一次性移除元素上的所有滤镜,请使用 filter-none 实用程序:

html
<div class="blur-md invert hue-rotate-180 md:filter-none">
  <!-- ... -->
</div>

这在你想有条件地移除滤镜时会很有用,比如在悬停时或在特定断点处。

有条件地应用

悬停、焦点和其他状态

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

html
<div class="hue-rotate-60 hover:hue-rotate-0">
  <!-- ... -->
</div>

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

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,比如响应式断点、暗模式、偏好减少动画等。例如,使用 md:hue-rotate-0 仅在中等屏幕尺寸及以上应用 hue-rotate-0 实用程序。

html
<div class="hue-rotate-60 md:hue-rotate-0">
  <!-- ... -->
</div>

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

使用自定义值

定制您的主题

默认情况下,Tailwind 包含一些通用的 hue-rotate 实用程序。您可以通过编辑 tailwind.config.js 文件中的 theme.hueRotatetheme.extend.hueRotate 来自定义这些值。

js
module.exports = {
  theme: {
    extend: {
      hueRotate: {			
        '-270': '-270deg',	
        270: '270deg',		
      }						
    }
  }
}

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

任意值

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

html
<div class="hue-rotate-[270deg]">
  <!-- ... -->
</div>

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

Released under the MIT License.