如何设置FormControlLabel字体大小的样式

Lam*_*ert 6 material-ui

如何在Material-UI FormControlLabel上设置嵌入式字体大小?以下尝试不起作用。

const styles: any = createStyles({
   formControlLabel: { fontSize: '0.6rem', 
   '& label': { fontSize: '0.6rem' } }
});

<FormControlLabel style={styles.formControlLabel}
  control={<Checkbox value="Hello" color="primary" />}
           label="World"
/>
Run Code Online (Sandbox Code Playgroud)

Sou*_*ngh 10

使用材质框fontSize而不是给出外部样式。

 <FormControlLabel
        control={<Checkbox name="checkbox" />}
        label={
             <Box component="div" fontSize={15}>
                Small
              </Box>
        }
  />
Run Code Online (Sandbox Code Playgroud)


Pra*_*gam 10

typographyFormControlLabel作为 prop公开。在 Mui V5 中测试并工作。https://mui.com/api/form-control-label/#props

<FormControlLabel
  componentsProps={{ typography: { variant: 'h3' } }}
/>
Run Code Online (Sandbox Code Playgroud)


小智 9

您可以将标签定义为Typography组件,然后在其中应用样式:

<FormControlLabel 
    control={<Checkbox value="Hello" color="primary" />}
    label={<Typography style={styles.formControlLabel}>World</Typography>}
/>
Run Code Online (Sandbox Code Playgroud)

  • 在最近的版本中,它应该是`label={&lt;Typography className={styles.formControlLabel}&gt;World&lt;/Typography&gt;}`。 (9认同)

bas*_*sse 8

在 MUI v5 中你可以这样做:

<FormControlLabel
  label={
    <Typography sx={{ fontSize: 16 }}>
      Label Text
    </Typography>
  }
  control={<Switch />}
/>
Run Code Online (Sandbox Code Playgroud)


kee*_*mor 5

使用theme.ts 中的overrides部分

export default createMuiTheme({
  overrides: {
    MuiFormControlLabel: {
      label: {
        fontSize: 14,
      },
    },
});
Run Code Online (Sandbox Code Playgroud)