Typography API
想要学习更多组件属性和 CSS API,可以查阅 React Typography 组件的 API 文档。
导入
import Typography from '@mui/material/Typography';
// 或
import { Typography } from '@mui/material';
组件名称
The nameMuiTypography
can be used when providing default props or style overrides in the theme.属性
原生(Native) 组件的属性也是可用的。
名称 | 类型 | 默认值 | 描述 |
---|---|---|---|
align | 'center' | 'inherit' | 'justify' | 'left' | 'right' | 'inherit' | Set the text-align on the component. |
children | node | The content of the component. | |
classes | object | Override or extend the styles applied to the component. See CSS API below for more details. | |
component | elementType | The component used for the root node. Either a string to use a HTML element or a component. | |
gutterBottom | bool | false | If true , the text will have a bottom margin. |
noWrap | bool | false | If true , the text will not wrap, but instead will truncate with a text overflow ellipsis.Note that text overflow can only happen with block or inline-block level elements (the element needs to have a width in order to overflow). |
paragraph | bool | false | If true , the element will be a paragraph element. |
sx | Array<func | object | bool> | func | object | The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details. | |
variant | 'body1' | 'body2' | 'button' | 'caption' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'inherit' | 'overline' | 'subtitle1' | 'subtitle2' | string | 'body1' | Applies the theme typography styles. |
variantMapping | object | { h1: 'h1', h2: 'h2', h3: 'h3', h4: 'h4', h5: 'h5', h6: 'h6', subtitle1: 'h6', subtitle2: 'h6', body1: 'p', body2: 'p', inherit: 'p', } | The component maps the variant prop to a range of different HTML element types. For instance, subtitle1 to <h6> . If you wish to change that mapping, you can provide your own. Alternatively, you can use the component prop. |
作为一个 CSS 实用工具, Typography 组件也支持所有
系统
属性。 您可以将它们作为props在组件上直接使用。ref
则会被传递到根元素中。CSS
规则名称 | 全局类名 | 描述 |
---|---|---|
root | .MuiTypography-root | Styles applied to the root element. |
body2 | .MuiTypography-body2 | Styles applied to the root element if variant="body2" . |
body1 | .MuiTypography-body1 | Styles applied to the root element if variant="body1" . |
caption | .MuiTypography-caption | Styles applied to the root element if variant="caption" . |
button | .MuiTypography-button | Styles applied to the root element if variant="button" . |
h1 | .MuiTypography-h1 | Styles applied to the root element if variant="h1" . |
h2 | .MuiTypography-h2 | Styles applied to the root element if variant="h2" . |
h3 | .MuiTypography-h3 | Styles applied to the root element if variant="h3" . |
h4 | .MuiTypography-h4 | Styles applied to the root element if variant="h4" . |
h5 | .MuiTypography-h5 | Styles applied to the root element if variant="h5" . |
h6 | .MuiTypography-h6 | Styles applied to the root element if variant="h6" . |
subtitle1 | .MuiTypography-subtitle1 | Styles applied to the root element if variant="subtitle1" . |
subtitle2 | .MuiTypography-subtitle2 | Styles applied to the root element if variant="subtitle2" . |
overline | .MuiTypography-overline | Styles applied to the root element if variant="overline" . |
inherit | .MuiTypography-inherit | Styles applied to the root element if variant="inherit" . |
alignLeft | .MuiTypography-alignLeft | Styles applied to the root element if align="left" . |
alignCenter | .MuiTypography-alignCenter | Styles applied to the root element if align="center" . |
alignRight | .MuiTypography-alignRight | Styles applied to the root element if align="right" . |
alignJustify | .MuiTypography-alignJustify | Styles applied to the root element if align="justify" . |
noWrap | .MuiTypography-noWrap | Styles applied to the root element if nowrap={true} . |
gutterBottom | .MuiTypography-gutterBottom | Styles applied to the root element if gutterBottom={true} . |
paragraph | .MuiTypography-paragraph | Styles applied to the root element if paragraph={true} . |
您可以使用组件自定义选项对组件进行个性化:
- With a global class name.
- With a rule name as part of the component's
styleOverrides
property in a custom theme.