css - Material-ui 样式类型覆盖
问题描述
当我MuiIconButton-root
将 MuiSvgIcon 与fontSizeSmall
.
import React from 'react'
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
const theme = createMuiTheme({
overrides: {
MuiSvgIcon: {
fontSizeSmall: {
padding: "5px"
}
}
}
});
export default function Root(props) {
return (
<ThemeProvider theme={theme}>
<MyApp />
</ThemeProvider>
)
}
我已经修改MuiSvgIcon
了,但是不能修改MuiButtonBase-root
。有没有办法覆盖MuiIconButton-root
我使用 small 时的填充值MuiSvgIcon
?
跟着图片:
解决方案
是的,您可以像这样覆盖 root 的样式,我不会创建您的确切场景,但我将使用 Material UI 中的按钮向您展示相同的功能,首先获取所有需要的文件:
npm install @material-ui/styles
npm install @material-ui/core
进而:
//other react imports
import { makeStyles, withStyles } from '@material-ui/core/styles'; //you need to include this to change the style
import Button from '@material-ui/core/Button'; //this is just the button
const useStyles = theme => ({
root: {
'& > *': {
margin: theme.spacing(1),
},
},
button: {
fontSize: "16px",
fontWeight: "600",
textAlign: "center",
border: "none",
cursor: "pointer",
color: "#fff",
backgroundColor: "#C8385E"
}
});
class Welcome extends React.Component {
render() {
return (<div>
<Button
className={classes.button}
variant="contained" component="span">
BUTTON TEXT
</Button>
</div>);
}
}
export default withStyles(useStyles)(Welcome);
您需要像上面显示的那样导出类,包括“withStyles”并传入您拥有的样式,这里称为“useStyles”,然后传递类名。这样您就可以在 UseStyles 中编辑样式,它实际上会在屏幕上显示这些更改。
推荐阅读
- javascript - Firebase/React:在创建之前获取文档 ID
- html - 为什么 Bootstrap 不应用 6:3:3 的列比例?
- postgresql - 查询错误 (7): 错误: "\" LINE 1 处或附近的语法错误: \copy people (supervisor_lname, supervisor_fname, lname, fn
- javascript - Amcharts 4 周期格式问题和可能的周期刻度
- javascript - 与函数一起使用时,节点子进程(Spawn)未正确返回数据
- oracle - ORA-01086 - 保存点从未在此会话中建立或无效
- kubernetes - 创建 pvc 后 Kubernetes 部署卡在挂起
- reactjs - 如何在反应羽毛笔中插入主题标签和提及的链接?
- sql - SQL递归查询获取部门代码
- ansible - 将时间戳存储为常量值