间距
Use the theme.spacing() helper to create consistent spacing between the elements of your UI.
Material-UI uses a recommended 8px scaling factor by default.
const theme = createMuiTheme();
theme.spacing(2) // = 8 * 2
Custom spacing
您可以通过提供以下内容来更改间距转换值:
- 一个数字
const theme = createMuiTheme({
spacing: 4,
});
theme.spacing(2) // = 4 * 2
- a function
const theme = createMuiTheme({
spacing: factor => `${0.25 * factor}rem`, // (Bootstrap strategy)
});
theme.spacing(2); // = 0.25 * 2rem = 0.5rem = 8px
- an array
const theme = createMuiTheme({
spacing: [0, 4, 8, 16, 32, 64],
});
theme.spacing(2); // = 8
多个参数
theme.spacing()
最多接受4个参数。 You can use the arguments to reduce the boilerplate.
-padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`, // '8px 16px'
+padding: theme.spacing(1, 2), // '8px 16px'
Mixing string values is also supported:
margin: theme.spacing(1, 'auto'), // '8px auto'