控制元素 (Element) 背景的功能
使用 bg-gradient-{direction}
中的任一種功能,搭配 gradient color stop 功能使用,即可讓元素有線性漸層效果。
<div class="bg-gradient-to-r from-yellow-400 via-red-500 to-pink-500 ..."></div>
如要讓元素的背景圖片有響應式效果,可在現有背景圖片功能前加上前綴詞 {screen}:
。例如:中型或以上的螢幕尺寸使用 md:bg-gradient-to-r
以套用 bg-gradient-to-r
功能。
<div class="bg-gradient-to-l md:bg-gradient-to-r ..."></div>
更多有關 Tailwind 響應式設計功能的資訊,可參考 響應式設計 文件。
Tailwind 預設將用來創造線性漸層背景效果的背景圖片功能分為八大方向。
你可以編輯 tailwind.config.js
中的 theme.backgroundImage
來加入自訂的背景圖片。
// tailwind.config.js
module.exports = {
theme: {
extend: {
backgroundImage: {
+ 'hero-pattern': "url('/img/hero-pattern.svg')",
+ 'footer-texture': "url('/img/footer-texture.png')",
}
}
}
}
它們不僅是漸層,也可是任何你需要的背景圖片。
這些 classes 可使用 bg-{key}
格式,例如 hero-pattern
能變成 bg-hero-pattern
。
默認情況下, 只有 響應式 的 background image 變化模式 (variants) 會產生。
在 tailwind.config.js
的 variants
區塊中變更 backgroundImage
屬性來決定有哪些變化模式會生成。
舉個例子來說,這個設定將會生成 響應式 和 hover 的變化模式。
// tailwind.config.js
module.exports = {
variants: {
extend: {
// ...
+ backgroundImage: ['responsive', 'hover'],
}
}
}
如果你不打算在專案中使用 background image 功能,可以在你的設定檔裡的 corePlugins
屬性中將 backgroundImage
設定為 false
來停用功能:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ backgroundImage: false,
}
}