1. 过滤器
  2. 背景不透明度

Quick reference

Class
Properties
backdrop-opacity-0backdrop-filter: opacity(0);
backdrop-opacity-5backdrop-filter: opacity(0.05);
backdrop-opacity-10backdrop-filter: opacity(0.1);
backdrop-opacity-15backdrop-filter: opacity(0.15);
backdrop-opacity-20backdrop-filter: opacity(0.2);
backdrop-opacity-25backdrop-filter: opacity(0.25);
backdrop-opacity-30backdrop-filter: opacity(0.3);
backdrop-opacity-35backdrop-filter: opacity(0.35);
backdrop-opacity-40backdrop-filter: opacity(0.4);
backdrop-opacity-45backdrop-filter: opacity(0.45);
backdrop-opacity-50backdrop-filter: opacity(0.5);
backdrop-opacity-55backdrop-filter: opacity(0.55);
backdrop-opacity-60backdrop-filter: opacity(0.6);
backdrop-opacity-65backdrop-filter: opacity(0.65);
backdrop-opacity-70backdrop-filter: opacity(0.7);
backdrop-opacity-75backdrop-filter: opacity(0.75);
backdrop-opacity-80backdrop-filter: opacity(0.8);
backdrop-opacity-85backdrop-filter: opacity(0.85);
backdrop-opacity-90backdrop-filter: opacity(0.9);
backdrop-opacity-95backdrop-filter: opacity(0.95);
backdrop-opacity-100backdrop-filter: opacity(1);

基础用法

控制背景滤镜的不透明度

使用 backdrop-opacity-* 实用程序来控制应用于元素的其他背景过滤器的不透明度。

backdrop-opacity-10

backdrop-opacity-60

backdrop-opacity-95

<div class="backdrop-opacity-10 backdrop-invert bg-white/30 ...">
  <!-- ... -->
</div>
<div class="backdrop-opacity-60 backdrop-invert bg-white/30 ...">
  <!-- ... -->
</div>
<div class="backdrop-opacity-95 backdrop-invert 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-opacity-60 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-opacity-60 来仅 在 hover应用 backdrop-opacity-60.

<div class="backdrop-opacity-100 hover:backdrop-opacity-60">
  <!-- ... -->
</div>

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

断点和媒体查询

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

<div class="backdrop-opacity-100 md:backdrop-opacity-60">
  <!-- ... -->
</div>

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


使用自定义值

定制你的主题

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

tailwind.config.js
module.exports = {
  theme: {
    extend: {
      backdropOpacity: {
        15: '.15',
      }
    }
  }
}

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

任意值

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

<div class="backdrop-opacity-[.15]">
  <!-- ... -->
</div>

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