gpt4 book ai didi

reactjs - Material UI - 排版 fontSize

转载 作者:行者123 更新时间:2023-12-04 03:51:59 27 4
gpt4 key购买 nike

最近我将我的 Material UI 版本从 3.9.4 升级到 4.11.0,我不得不在主题样式覆盖上替换这些:
enter image description here
为避免这些警告:
enter image description here
但是我需要将 fontSize 样式放在 !important 中,因为它正在处理在不同网页上呈现的小部件,如果我不使用 !important,那么样式将被页面的样式覆盖,是否有如何在最新版本的排版 fontSize 样式上使用 !important 标签?
我尝试使用 fontSize: `16 !important`,fontSize: [[16], ['!important']没有成功。
欢迎任何帮助,谢谢您的建议!!!
编辑:
在覆盖部分,它甚至将样式作为字符串接收,但在 排版 部分,即使使用 @Ryan Cogswell 建议,它仍然向我发出相同的警告

const Theme = createMuiTheme({
root: {
display: 'flex',
},
palette: {
primary: {
main: '#052d4f',
},
secondary: {
main: '#2376b8',
},
},
typography: {
fontFamily: 'Arial, Helvetica, sans-serif !important',
fontSize: [16, "!important"],
},
overrides: {
MuiTypography: {
body2: {
fontFamily: 'Arial, Helvetica, sans-serif !important',
fontSize: "16px !important",
},
subtitle1: {
fontFamily: 'Arial',
fontSize: "16px !important",
},
},
MuiTablePagination: {
toolbar: {
fontSize: "14px !important",
}
},
MuiAutocomplete: {
root: {
paddingLeft: "15px",
paddingRight: "15px",
},
groupLabel: {
fontWeight: 700,
color: "black",
fontSize: "14px !important",
},
option: {
paddingTop: "0px",
paddingBottom: "0px",
fontSize: "14px !important",
height: "25px"
}
}
},
status: {
danger: 'orange',
},
});

最佳答案

您想要的语法是 fontSize: [16, "!important"] 。也可以将 16 放入数组中,但不能将 "!important" 放入数组中。
这是一个工作示例:

import React from "react";
import { ThemeProvider, createMuiTheme } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";

const theme = createMuiTheme({
overrides: {
MuiTypography: {
body2: {
fontSize: [16, "!important"]
}
}
}
});
export default function App() {
return (
<ThemeProvider theme={theme}>
<div className="App">
<Typography variant="body2">Hello CodeSandbox</Typography>
</div>
</ThemeProvider>
);
}
Edit fontSize override important
JSS 文档: https://cssinjs.org/jss-syntax?v=v10.4.0#modifier-important

关于reactjs - Material UI - 排版 fontSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64325780/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com