过滤
backdrop-filter: grayscale()
用于将背景灰度滤镜应用于元素的工具。
类 | 样式 |
---|---|
backdrop-grayscale | backdrop-filter: grayscale(100%); |
backdrop-grayscale-<number> | backdrop-filter: grayscale(<number>%); |
backdrop-grayscale-(<custom-property>) | backdrop-filter: grayscale(var(<custom-property>)); |
backdrop-grayscale-[<value>] | backdrop-filter: grayscale(<value>); |
示例(Examples)
¥Examples
基本示例(Basic example)
¥Basic example
使用 backdrop-grayscale-50
和 backdrop-grayscale
等工具控制应用于元素背景的灰度效果:
¥Use utilities like backdrop-grayscale-50
and backdrop-grayscale
to control the grayscale effect applied to an element's backdrop:
backdrop-grayscale-0
backdrop-grayscale-50
backdrop-grayscale
<div class="bg-[url(/img/mountains.jpg)]"><div class="bg-white/30 backdrop-grayscale-0 ..."></div></div><div class="bg-[url(/img/mountains.jpg)]"><div class="bg-white/30 backdrop-grayscale-50 ..."></div></div><div class="bg-[url(/img/mountains.jpg)]"><div class="bg-white/30 backdrop-grayscale-200 ..."></div></div>
使用自定义值(Using a custom value)
¥Using a custom value
使用 backdrop-grayscale-[<value>]
语法 根据完全自定义的值设置 backdrop grayscale:
<div class="backdrop-grayscale-[0.5] ..."> <!-- ... --></div>
对于 CSS 变量,还可以使用 backdrop-grayscale-(<custom-property>)
语法:
<div class="backdrop-grayscale-(--my-backdrop-grayscale) ..."> <!-- ... --></div>
这只是简写,用于 backdrop-grayscale-[var(<custom-property>)]
它会自动为你添加 var()
函数。
响应式设计(Responsive design)
¥Responsive design
在 backdrop-filter: grayscale()
工具前面使用断点变体如 md:
仅在 medium 屏幕尺寸及以上时应用工具:
<div class="backdrop-grayscale md:backdrop-grayscale-0 ..."> <!-- ... --></div>
请参阅 变体文档 详细了解如何使用变体。