Tailwind CSS 自定义颜色应用于文本但不适用于 ReactJS 中的背景
Tailwind CSS custom color applying to text but not background in ReactJS
好吧,我的问题不仅仅是标题。
我一直在尝试在我的 React 应用程序中添加自定义颜色,并且 运行 遇到了多个问题。
这是我的一些代码:
// tailwind.config.js
module.exports = {
purge: [],
theme: {
colors: {
primary: "var(--color-primary)",
secondary: "var(--color-secondary)",
},
extend: {},
},
variants: {},
plugins: [],
};
// tailwind.css
@tailwind base;
@tailwind components;
@tailwind utilities;
.theme-TCD {
--color-primary: #411218;
--color-secondary: #e8982e;
}
我最初使用 yarn this tutorial using npm but that would not work. When I follow this tutorial 设置我的 React 应用程序,一些自定义颜色应用正确。
仅应用自定义文本颜色,不应用背景颜色。
自定义文本颜色仅适用于 React 元素。它在普通 HTML 标签中不起作用。
即
import React from "react";
import Hello from "./hello";
function App() {
return (
<div className="theme-TCD">
<h1 className="text-primary">Hello World!</h1> // This does not work
<Hello /> // This works
</div>
);
}
export default App;
尝试颠倒 tailwind.css 文件中的出现顺序并更改为:
:root {
--color-primary: #411218;
--color-secondary: #e8982e;
}
@tailwind base;
@tailwind components;
@tailwind utilities;
好吧,我的问题不仅仅是标题。 我一直在尝试在我的 React 应用程序中添加自定义颜色,并且 运行 遇到了多个问题。
这是我的一些代码:
// tailwind.config.js
module.exports = {
purge: [],
theme: {
colors: {
primary: "var(--color-primary)",
secondary: "var(--color-secondary)",
},
extend: {},
},
variants: {},
plugins: [],
};
// tailwind.css
@tailwind base;
@tailwind components;
@tailwind utilities;
.theme-TCD {
--color-primary: #411218;
--color-secondary: #e8982e;
}
我最初使用 yarn this tutorial using npm but that would not work. When I follow this tutorial 设置我的 React 应用程序,一些自定义颜色应用正确。
仅应用自定义文本颜色,不应用背景颜色。
自定义文本颜色仅适用于 React 元素。它在普通 HTML 标签中不起作用。 即
import React from "react";
import Hello from "./hello";
function App() {
return (
<div className="theme-TCD">
<h1 className="text-primary">Hello World!</h1> // This does not work
<Hello /> // This works
</div>
);
}
export default App;
尝试颠倒 tailwind.css 文件中的出现顺序并更改为:
:root {
--color-primary: #411218;
--color-secondary: #e8982e;
}
@tailwind base;
@tailwind components;
@tailwind utilities;