有没有办法在顺风配置中定义不同的颜色,以便在不使用深色模式的情况下应用深色模式dark
选择器?
目前我有一个像这样的对象:
const colors = {
light: {
red: {
100: "#880808",
...
}
},
dark: {
red: {
100: "red",
...
}
},
}
I'd like只是使用red-100
并自动映射颜色(只需通过bg-red-100
) 无需指定bg-red-100 dark:bg-red-dark-100
您可以在 CSS 文件中定义颜色,如下所示:
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--color-primary: 247 147 34;
--color-text: 33 33 33;
--color-success: 0 200 81;
--color-info: 51 181 229;
--color-warn: 255 187 51;
--color-error: 254 78 78;
}
:root[class~="dark"] {
--color-primary: 247 147 34;
--color-text: 33 33 33;
--color-success: 0 200 81;
--color-info: 51 181 229;
--color-warn: 255 187 51;
--color-error: 254 78 78;
}
}
然后在你的中使用这个配置tailwind.config.js
:
/** @type {import('tailwindcss').Config} */
module.exports = {
darkMode: "class",
theme: {
colors: {
primary: "rgb(var(--color-primary) / <alpha-value>)",
text: "rgb(var(--color-text) / <alpha-value>)",
success: "rgb(var(--color-success) / <alpha-value>)",
info: "rgb(var(--color-info) / <alpha-value>)",
warn: "rgb(var(--color-warn) / <alpha-value>)",
error: "rgb(var(--color-error) / <alpha-value>)",
transparent: "transparent",
current: "currentColor",
},
}
现在,如果您在文档根上设置深色类,颜色会自动更改
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)