1. 过滤器
  2. 背景亮度

Quick reference

Class
Properties
backdrop-brightness-0backdrop-filter: brightness(0);
backdrop-brightness-50backdrop-filter: brightness(.5);
backdrop-brightness-75backdrop-filter: brightness(.75);
backdrop-brightness-90backdrop-filter: brightness(.9);
backdrop-brightness-95backdrop-filter: brightness(.95);
backdrop-brightness-100backdrop-filter: brightness(1);
backdrop-brightness-105backdrop-filter: brightness(1.05);
backdrop-brightness-110backdrop-filter: brightness(1.1);
backdrop-brightness-125backdrop-filter: brightness(1.25);
backdrop-brightness-150backdrop-filter: brightness(1.5);
backdrop-brightness-200backdrop-filter: brightness(2);

基础用法

控制背景亮度

使用 backdrop-brightness-* 实用程序来控制元素的背景亮度。

backdrop-brightness-50

backdrop-brightness-125

backdrop-brightness-200

<div class="backdrop-brightness-50 bg-white/30 ...">
  <!-- ... -->
</div>
<div class="backdrop-brightness-125 bg-white/30 ...">
  <!-- ... -->
</div>
<div class="backdrop-brightness-200 bg-white/30 ...">
  <!-- ... -->
</div>

移除背景滤镜

To remove all of the backdrop filters on an element at once, use the backdrop-filter-none utility:

<div class="backdrop-blur-md backdrop-brightness-150 md:backdrop-filter-none">
  <!-- ... -->
</div>

This can be useful when you want to remove backdrop filters conditionally, such as on hover or at a particular breakpoint.


有条件申请

悬停、聚焦和其他状态

Tailwind 允许您使用变体修饰符有条件地在不同状态下应用实用程序类。例如,使用 hover:backdrop-brightness-150 来仅 在 hover应用 backdrop-brightness-150.

<div class="backdrop-brightness-110 hover:backdrop-brightness-150">
  <!-- ... -->
</div>

详细了解, 请参考 Hover, Focus, & Other States 文档.

断点和媒体查询

您还可以使用变体修饰符来定位媒体查询,例如响应式断点、暗模式、首选减少运动等。例如, 使用 md:backdrop-brightness-150 来应用 backdrop-brightness-150 程序,适用于中等屏幕尺寸及以上。

<div class="backdrop-brightness-110 md:backdrop-brightness-150">
  <!-- ... -->
</div>

进一步了解,请参考 响应式设计, 暗黑模式 媒体查询.


使用自定义值

定制你的主题

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

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      backdropBrightness: {
        25: '.25',
        175: '1.75',
      }
    }
  }
}

theme customization 文档中了解有关自定义默认主题的更多信息。

任意值

如果您需要使用一次性的 backdrop-brightness值,而该值没有必要包含在主题中,请使用方括号动态生成属性,使用任意值。

<div class="backdrop-brightness-[1.75]">
  <!-- ... -->
</div>

进一步了解,请参考 任意值 文档.