將背景對比濾鏡套用在元素的功能
將 backdrop-contrast-{amount?}
功能跟 backdrop-filter
功能搭配使用,即可控制元素的背景對比。
<div class="backdrop-filter backdrop-contrast-125 ...">
<!-- ... -->
</div>
如要讓元素的背景對比有響應式效果,可在現有背景對比功能前加上前綴詞 {screen}:
。例如:中型或以上的螢幕尺寸使用 md:backdrop-contrast-150
以套用 backdrop-contrast-150
功能。
<div class="backdrop-filter backdrop-contrast-110 md:backdrop-contrast-150 ...">
<!-- ... -->
</div>
更多有關 Tailwind 響應式設計功能的資訊,可參考 響應式設計 文件。
你可以在tailwind.config.js
的theme
區塊中,使用backdropContrast
這個 key 來客製化你要的backdrop-contrast
效果。
// tailwind.config.js
module.exports = {
theme: {
+ extend: {
+ backdropContrast: {
+ 25: '.25',
+ }
+ }
}
}
更多有關客製化預設主題的資訊,可參考主題客製化文件。
你可以調整 Tailwind config. 中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',
}
}
}
默認情況下, 只有 響應式 的 backdrop contrast 變化模式 (variants) 會產生。
在 tailwind.config.js
的 variants
區塊中變更 backdropContrast
屬性來決定有哪些變化模式會生成。
舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。
// tailwind.config.js
module.exports = {
variants: {
extend: {
// ...
+ backdropContrast: ['responsive', 'hover'],
}
}
}
如果你不打算在專案中使用 backdrop contrast 功能,可以在你的設定檔裡的 corePlugins
屬性中將 backdropContrast
設定為 false
來停用功能:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ backdropContrast: false,
}
}