css - 如何更改材质ui卡中子标题的颜色?
问题描述
我有一个具有深色背景颜色的 Material UI Card,所以我需要文本为白色。我应用的样式似乎成功更改了 CardHeader 标题而不是子标题?我怎样才能让副标题也变成白色?
我的代码如下:
const useStyles = makeStyles(theme => ({
menuColor: {
backgroundColor: theme.palette.primary.main,
color: '#ffffff',
},
}));
const ProfileUser = () => {
const classes = useStyles();
return (
<Card elevation={0} className={classes.menuColor}>
<CardHeader
avatar={<Avatar />}
title="Person name"
titleTypographyProps="h4"
subheaderTypographyProps="body1"
subheader="Person role"
/>
</Card>
);
};
export default ProfileUser;
解决方案
您可以将节点传递给 subheader 道具。
实现此目的的一种方法是创建一个具有所需颜色的新 makeStyle 类:
const useStyles = makeStyles(theme => ({
menuColor: {
backgroundColor: theme.palette.primary.main,
color: '#ffffff',
},
subColor: {
color: '#000000'
}
}));
然后,您可以使用此类将某些内容传递给 subheader 道具(可能最适合 MUI 排版组件):
<Card elevation={0} className={classes.menuColor}>
<CardHeader
avatar={<Avatar />}
title="Person name"
titleTypographyProps="h4"
subheaderTypographyProps="body1"
subheader={<Typography className={classes.subColor}>Person role</Typography>}
/>
</Card>;
推荐阅读
- javascript - 从 Firebase 存储中获取非百分比编码的 URL
- ios - 如何通过 XCode 10 和 Cordova 构建应用程序?
- bash - 如何检查以特定字符串开头的目录是否存在?
- javascript - 具有多个过滤器的过滤器表
- javascript - 如何在 React JS 中添加图像
- javascript - 访问javascript对象的条件属性
- scala - 如何过滤 Scala Map List 值
- node.js - 如何在 vscode 上使用 npm 命令
- elasticsearch - 如何使用 logstash+jdbc 和数据库触发器对 Elasticsearch 进行增量加载
- javascript - 如何更改模式窗口的内容