1. 滤镜
  2. 对比度

滤镜

滤镜:contrast()

用于对元素应用对比度滤镜的工具。

ClassStyles
contrast-<number>
filter: contrast(<number>%);
contrast-(<custom-property>)
filter: contrast(var(<custom-property>));
contrast-[<value>]
filter: contrast(<value>);

示例

基本示例

使用 contrast-50contrast-100 等工具来控制元素的对比度:

contrast-50

contrast-100

contrast-125

contrast-200

<img class="contrast-50 ..." src="/img/mountains.jpg" />
<img class="contrast-100 ..." src="/img/mountains.jpg" />
<img class="contrast-125 ..." src="/img/mountains.jpg" />
<img class="contrast-200 ..." src="/img/mountains.jpg" />

使用自定义值

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

<img class="contrast-[.25] ..." src="/img/mountains.jpg" />

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

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

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

响应式设计

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

<img class="contrast-125 md:contrast-150 ..." src="/img/mountains.jpg" />

Learn more about using variants in the variants documentation.