Just-in-Time: The Next Generation of Tailwind CSS
Tailwind CSS on GitHub

Backdrop Filter

Tailwind CSS version
v2.1+

Utilities for enabling and disabling backdrop filters on an element.

Default class reference

Class
Properties
backdrop-filterbackdrop-filter: var(--tw-backdrop-blur) var(--tw-backdrop-brightness) var(--tw-backdrop-contrast) var(--tw-backdrop-grayscale) var(--tw-backdrop-hue-rotate) var(--tw-backdrop-invert) var(--tw-backdrop-opacity) var(--tw-backdrop-saturate) var(--tw-backdrop-sepia);
backdrop-filter-nonebackdrop-filter: none;

Usage

Use the backdrop-filter utility to enable backdrop filters (in combination with other backdrop filter utilities like backdrop-blur or backdrop-grayscale), and the backdrop-filter-none utility to remove filters.

<div class="backdrop-filter backdrop-grayscale backdrop-blur-md backdrop-contrast-200 ...">
  <!-- ... -->
</div>

Responsive

To control backdrop filters at a specific breakpoint, add a {screen}: prefix to any existing backdrop filter utility. For example, use md:backdrop-filter-none to apply the backdrop-filter-none utility at only medium screen sizes and above.

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

For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.

Customizing

Variants

默认情况下, 针对 backdrop-filter 功能类,只生成 responsive 变体。

您可以通过修改您的 tailwind.config.js 文件中的 variants 部分中的 backdropFilter 属性来控制为 backdrop-filter 功能生成哪些变体。

例如,这个配置将生成 hover and focus 变体:

  // tailwind.config.js
  module.exports = {
    variants: {
      extend: {
        // ...
+       backdropFilter: ['hover', 'focus'],
      }
    }
  }

Disabling

如果您不打算在您的项目中使用 backdrop-filter 功能,您可以通过在配置文件的 corePlugins 部分将 backdropFilter 属性设置为 false 来完全禁用它们:

  // tailwind.config.js
  module.exports = {
    corePlugins: {
      // ...
+     backdropFilter: false,
    }
  }