1. 滤镜
  2. 滤镜

滤镜

滤镜

用于将滤镜应用于元素的工具。

ClassStyles
filter-none
filter: none;
filter-(<custom-property>)
filter: var(<custom-property>);
filter-[<value>]
filter: <value>;

示例

基本示例

使用如 blur-xsgrayscale 的工具将滤镜应用于元素:

blur-xs

grayscale

combined

<img class="blur-xs" src="/img/mountains.jpg" />
<img class="grayscale" src="/img/mountains.jpg" />
<img class="blur-xs grayscale" src="/img/mountains.jpg" />

您可以组合以下滤镜工具:blur, brightness, contrast, drop-shadow, grayscale, hue-rotate, invert, saturate, 和 sepia

移除滤镜

使用 filter-none 工具来移除应用于元素的所有滤镜:

<img class="blur-md brightness-150 invert md:filter-none" src="/img/mountains.jpg" />

使用自定义值

Use the filter-[<value>] syntax to set the filter based on a completely custom value:

<img class="filter-[url('filters.svg#filter-id')] ..." src="/img/mountains.jpg" />

For CSS variables, you can also use the filter-(<custom-property>) syntax:

<img class="filter-(--my-filter) ..." src="/img/mountains.jpg" />

This is just a shorthand for filter-[var(<custom-property>)] that adds the var() function for you automatically.

悬停时应用

Prefix a filter utility with a variant like hover:* to only apply the utility in that state:

<img class="blur-sm hover:filter-none ..." src="/img/mountains.jpg" />

Learn more about using variants in the variants documentation.

响应式设计

Prefix a filter utility with a breakpoint variant like md: to only apply the utility at medium screen sizes and above:

<img class="blur-sm md:filter-none ..." src="/img/mountains.jpg" />

Learn more about using variants in the variants documentation.