【发布时间】:2021-03-07 06:42:42
【问题描述】:
我有一个使用 Material UI 构建的 React 应用程序。我创建了自己的主题覆盖(请参阅下面的摘录),但字体的颜色需要为紫色 #391960,而不是 rgba(0, 0, 0, 0.87)。如何覆盖整个网站的默认字体颜色?
这是我的主题的摘录
import { createMuiTheme } from "@material-ui/core";
const theme = createMuiTheme({
palette: {
text: {
light: "#ffffff",
main: "#391960",
dark: "#140b1d",
},
});
export default theme;
我希望在我的 theme.js 文件中添加上述内容会导致所有字体颜色更改为 #391960,因为我没有对组件中的字体应用任何样式。例如:
import theme from "./styles/theme";
<ThemeProvider theme={theme}>
<Typography variant="h1" component="h1">
Page Title
</Typography>
</ThemeProvider>
但是,上述 Typography 组件中的文本仍然是深灰色。我成功地使用以下代码更改了此排版组件的大小,因此这证明我将主题正确地拉入组件中:
typography: {
h1: {
fontSize: "2rem",
fontWeight: 700,
},
如果我不能使用 theme.js 文件设置站点范围的颜色,我在想我可以有一个全局样式表,它以某种方式从主题中提取正确的颜色?例如(我知道这行不通!)
body {
color: theme.palette.main
}
任何帮助将不胜感激!
谢谢,
凯蒂
【问题讨论】:
标签: css reactjs material-ui styles jsx