我正在使用 Tailwind 應用背景影像。我有單獨的 CSS 檔案。
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
body {
@apply bg-[url('./2.PNG')];
}
這是我的代碼 Image 正在使用 background-image 屬性,但不適用于 Tailwind。
uj5u.com熱心網友回復:
您使用的語法bg-[..]僅在 Tailwind v3.x 中與他們的JIT 編譯器結合使用。
對于 Tailwind v2.x,您可以在此處閱讀有關如何正確實作背景影像的資訊。
TL;博士:
// tailwind.config.js
module.exports = {
theme: {
extend: {
backgroundImage: {
'custom-background-image-name': "url('path-to-image/image.png')",
}
}
}
}
然后像這樣使用它
@layer base {
body {
@apply bg-custom-background-image-name;
}
}
uj5u.com熱心網友回復:
試試bg-[image:url('2.PNG')]。沒有image:順風不知道bg-是背景顏色還是影像。
編輯:僅適用于順風 v3.x。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/432992.html
