【问题标题】:Material-UI: Customize theme Font Size then some component layout will be abnormalMaterial-UI:自定义主题字体大小会导致部分组件布局异常
【发布时间】:2021-11-08 22:27:32
【问题描述】:

我用的是 Material-UI 自定义主题然后设置字体大小为 20。

const themeConfig = {
  typography: {
    fontSize: 20,
  },
};

我发现快速拨号组件的图标变大了,但图标不在按钮的中心。 字体大小只影响SVG图标大小,按钮宽度和高度值和以前一样。

.MuiSpeedDialIcon-root {
    height: 24px;
}
.MuiFab-root {
    width: 56px;
    height: 56px;
}

我的问题是在主题配置中更改字体大小的好模式是什么?或者我需要自己在主题配置中设置所有组件的宽度、高度、边距等?

这里是 Material-UI 模块版本列表。

"@material-ui/core": "4.12.3",
"@material-ui/icons": "4.11.2",
"@material-ui/lab": "4.0.0-alpha.60",
"@material-ui/system": "4.12.1",

【问题讨论】:

    标签: material-ui


    【解决方案1】:

    .MuiSpeedDialIcon-root 中的height 设置为fontSize

    const themeConfig = {
      typography: {
        fontSize: 20,
      },
    
      overrides: {
        MuiSpeedDialIcon: {
          root: {
            height: 20
          }
        }
      }
    };
    

    【讨论】:

    • 我将material-ui版本升级到v5,让interface-ThemeOptions支持覆盖lab组件。升级后,我将主题配置-MuiSpeedDialIcon.root.height 设置为20.MuiSpeedDialIcon-root 的高度将为20px。它小于默认大小。 (24 像素)
    猜你喜欢
    • 2019-05-23
    • 2022-06-15
    • 1970-01-01
    • 2020-04-09
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    • 2019-10-10
    • 1970-01-01
    相关资源
    最近更新 更多