javascript - 覆盖材质 UI 主题的默认主题定义
问题描述
在材质 UI 默认主题中存在 (css) 类MuiTab-root
。其中,除其他外,设置字体粗细(基于主题的排版定义)。
.MuiTab-root {
font-weight: 600;
}
这是通过withStyles
使用createMuiTheme
函数生成的。在创建期间,它使用typography.fontWeightMedium
提供的对象来定义选项卡的字体粗细。我想做的是font-weight
将默认主题覆盖为“正常”。理想情况下,通过说明它应该使用typography.fontWeightNormal
,或者如果不这样做,手动覆盖字体粗细。
我试过手动覆盖字体粗细。然而这并没有奏效。
const theme = createMuiTheme({
typography: {
fontWeightMedium: 600,
},
overrides: {
'.MuiTab-root': {
fontWeight: 400,
}
}
});
使用 chrome 检查显示选项卡的 fontWeight 仍为 600(半粗体)。
如何在这里覆盖默认定义?- 或者我是否必须依赖我在组件中使用的自定义类?
解决方案
以下是手动覆盖的正确语法:
const theme = createMuiTheme({
overrides: {
MuiTab: {
root: {
fontWeight: 400
}
}
}
});
以下是相关文档:https ://material-ui.com/customization/components/#global-theme-override
推荐阅读
- javascript - href 点击触发选择选项的下拉菜单
- docker - 没有基本的身份验证凭据 - `docker push image_name`
- c# - 当 TextBox 失去焦点时在 ViewModel 中运行函数?
- java - Spring @Component 未正确读取 .properties 字段
- android - 从私人游戏商店 iFrame 中删除应用程序
- c# - 为什么这条 MVC 路线不起作用(ASP.Net Core 2.2)
- azure-api-management - 如何在 Azure API 管理的 set-body 中引发异常?
- powershell - 检查开关参数的正确方法是什么
- python - 使用 z3Py 证明两个表达式范围的等价/不同
- operating-system - VirtualBox上PCI Express(PCIe)配置空间访问问题