Tailwind CSS Backdrop Contrast

2022-08-11 09:59 更新

Backdrop Contrast

將背景對(duì)比度過濾器應(yīng)用于元素的實(shí)用程序。

Class
Properties
backdrop-contrast-0 --tw-backdrop-contrast: contrast(0);
backdrop-contrast-50 --tw-backdrop-contrast: contrast(.5);
backdrop-contrast-75 --tw-backdrop-contrast: contrast(.75);
backdrop-contrast-100 --tw-backdrop-contrast: contrast(1);
backdrop-contrast-125 --tw-backdrop-contrast: contrast(1.25);
backdrop-contrast-150 --tw-backdrop-contrast: contrast(1.5);
backdrop-contrast-200 --tw-backdrop-contrast: contrast(2);

用法

使用 ?backdrop-contrast-{amount}? 實(shí)用程序和 ?backdrop-filter? 實(shí)用程序來控制元素的背景對(duì)比度。

<div class="backdrop-filter backdrop-contrast-125 ...">
  <!-- ... -->
</div>

響應(yīng)式

要在特定斷點(diǎn)處控制元素的背景對(duì)比度,請(qǐng)?jiān)谌魏维F(xiàn)有的背景對(duì)比度實(shí)用程序中添加 ?{screen}:? 前綴。例如,使用 ?md:backdrop-contrast-150? 僅在中等屏幕尺寸及以上尺寸應(yīng)用 ?backdrop-contrast-150? 實(shí)用程序。

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

有關(guān) Tailwind 響應(yīng)式設(shè)計(jì)功能的更多信息,請(qǐng)查看響應(yīng)式設(shè)計(jì)文檔。

自定義

您可以使用 ?tailwind.config.js? 文件的 ?theme ?部分中的 ?backgroundContrast ?鍵自定義生成哪些 ?backdrop-contrast? 實(shí)用程序。

  // tailwind.config.js
  module.exports = {
    theme: {
     extend: {
       backdropContrast: {
         25: '.25',
       }
     }
    }
  }

主題自定義文檔中了解有關(guān)自定義默認(rèn)主題的更多信息。

Backdrop Contrast Scale

您可以在 Tailwind 配置中自定義 ?backdrop-contrast? 過濾器的值。

  // tailwind.config.js
  module.exports = {
    theme: {
      backdropContrast: {
        0: '0',
       25: '.25',
        50: '.5',
        75: '.75',
        100: '1',
        125: '1.25',
        150: '1.5',
        200: '2',
      }
    }
  }

變體

默認(rèn)情況下, 針對(duì) backdrop contrast 功能類,只生成 responsive 變體。

您可以通過修改您的 ?tailwind.config.js? 文件中的 ?variants ?部分中的 ?backdropContrast ?屬性來控制為 backdrop contrast 功能生成哪些變體。

例如,這個(gè)配置也將生成 hover and focus 變體:

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

禁用

如果您不打算在您的項(xiàng)目中使用 backdrop contrast 功能,您可以通過在配置文件的 ?corePlugins ?部分將 ?backdropContrast ?屬性設(shè)置為 ?false ?來完全禁用它們:

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


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)