【发布时间】:2019-06-20 10:52:13
【问题描述】:
我正在尝试将默认主题排版字体大小设置为根据断点进行更改。例如,当断点位于 {xs} 值时,将 theme.typography.h4.fontSize 更改为 '1.5rem'。在所有其他断点处,将其保留为默认值 ('2.125rem')。
我可以使用以下代码示例在组件中轻松做到这一点:
const useStyles = makeStyles(theme => ({
title: {
[theme.breakpoints.down('xs')]: {
fontSize: '1.5rem',
}
},
}))
但是,这意味着必须将相同的代码添加到每个包含 <Typography variant='h4'> 的组件中。如果我决定将值从 '1.5rem' 更改为 '1.25rem',我需要找到 <Typography variant='h4'> 的每个实例并手动更改它。
有没有办法给 createMuiTheme 添加断点,让它适用于所有实例?
我尝试了以下方法,但不起作用:
const defaultTheme = createMuiTheme()
const theme = createMuiTheme({
typography: {
h4: {
[defaultTheme.breakpoints.down('xs')]: {
fontSize: '1.5rem'
}
}
}
})
【问题讨论】:
标签: reactjs material-ui