简体   繁体   English

如何在 MUI React Framework 中更改暗模式下元素的字体大小?

[英]How To change Font size of element in dark mode in MUI React Framework?

i am using makestyles method for CSS in MUI now i want some if else condition for dark and light mode我在 MUI 中使用 CSS 的 makestyles 方法现在我想要一些如果其他条件用于暗模式和亮模式

const useStyles = makeStyles(theme => ({常量 useStyles = makeStyles(主题 => ({

titleNew: {
    color: theme.palette.text.primary,
    marginBottom: '8px',
    fontSize:"14px"
    // if  mode is light then font size 14px if modeis dark then fontsize 18px
    
},

subtitleNew: {
    marginBottom: '25px',
    color: theme.palette.text.primary,
},

})); }));

You can check the mode inside of the theme object and use a ternary:您可以检查theme对象内部的模式并使用三元:

fontSize: theme.palette.mode === 'light' ? '14px' : '18px'

Check out the docs for more information on dark mode/theming and how to get the user's preference:查看文档以获取有关暗模式/主题以及如何获得用户偏好的更多信息:

https://mui.com/material-ui/customization/dark-mode/#dark-mode-by-default https://mui.com/material-ui/customization/dark-mode/#dark-mode-by-default

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM