【发布时间】:2021-09-20 13:48:34
【问题描述】:
因此,当我在 materialUI 中应用自定义主题(特别是更改字体)时,一些组件会更改字体,而有些则不会,我不知道为什么。基本上,所有使用<Typography> 组件的导入组件,无论是否嵌套在其他materialUI 组件中,都不会获得应用的主题。
import classes from "./App.module.css";
import Form from "./components/Form";
import Text from "./components/Text";
import { createTheme, ThemeProvider } from "@material-ui/core";
const theme = createTheme({
typography: {
fontFamily: "Grey Qo",
fontSize: 25,
},
});
function App() {
return (
<div className={classes.wrapper}>
<ThemeProvider theme={theme}>
<Text></Text>
<Form></Form>
</ThemeProvider>
</div>
);
}
export default App;
在图片中,您可以看到表单字体和顶部按钮发生变化,因为它们不使用<Typography> 组件,但其余部分保持不变
这里也是导入的 React <Text> 组件的示例
import { Typography } from "@mui/material";
import { makeStyles } from "@material-ui/styles";
import React from "react";
import classes from "./Text.module.css";
const useStyles = makeStyles({
text: {
color: "#f0f0f0",
},
});
export default function Text() {
const uiClasses = useStyles();
return (
<div className={classes.wrapper}>
<Typography variant="h4" className={uiClasses.text}>
Learn code by watching others
</Typography>
<Typography className={uiClasses.text}>
See how expirienced developers solve problems in real-time. Watching
scripted tutorilas is great, but understanding how developers thinks is
invalubale
</Typography>
</div>
);
}
这个字体是为了让问题更明显,希望有人能帮忙。 tnx 高级
【问题讨论】:
标签: reactjs material-ui