跳至主要內容跳至主要內容

Typography(排版)API

React Typography 元件的 API 參考文件。瞭解這個匯出模組的 props、CSS 和其他 API。

示範

匯入

import Typography from '@mui/material/Typography';
// or
import { Typography } from '@mui/material';

閱讀關於最小化套件大小的指南,以瞭解差異。

Props(屬性)

原生元件的 props 也可使用。

名稱類型預設值描述
align(對齊)'center'
| 'inherit'
| 'justify'
| 'left'
| 'right'
'inherit'

設定元件的 text-align 屬性。

children(子節點)node-

元件的內容。

classes(類別)object-

覆寫或擴展應用於元件的樣式。

請參閱下方CSS 類別 API 以瞭解更多詳細資訊。

color(顏色)'primary'
| 'secondary'
| 'success'
| 'error'
| 'info'
| 'warning'
| 'textPrimary'
| 'textSecondary'
| 'textDisabled'
| string
-

元件的顏色。它同時支援預設和自訂主題顏色,自訂主題顏色可以按照調色盤客製化指南中所示的方式新增。

component(元件)elementType-

用於根節點的元件。可以是字串(使用 HTML 元素)或元件。

gutterBottom(下方間距)boolfalse

true,文字下方將有邊界。

noWrap(不換行)boolfalse

true,文字將不會換行,而是會以文字溢位省略符號截斷。
請注意,文字溢位僅會在區塊或行內區塊層級元素上發生(元素需要有寬度才能溢位)。

paragraph(段落)boolfalse

true,元素將會是段落元素。

sxArray<func
| object
| bool>
| func
| object
-

系統 prop,允許定義系統覆寫以及額外的 CSS 樣式。

請參閱`sx` 頁面以瞭解更多詳細資訊。

variant(變體)'body1'
| 'body2'
| 'button'
| 'caption'
| 'h1'
| 'h2'
| 'h3'
| 'h4'
| 'h5'
| 'h6'
| 'inherit'
| 'overline'
| 'subtitle1'
| 'subtitle2'
| string
'body1'

套用主題排版樣式。

variantMapping(變體映射)object{ h1: 'h1', h2: 'h2', h3: 'h3', h4: 'h4', h5: 'h5', h6: 'h6', subtitle1: 'h6', subtitle2: 'h6', body1: 'p', body2: 'p', inherit: 'p', }

元件將 variant prop 映射到一系列不同的 HTML 元素類型。例如,subtitle1 映射到 <h6>。如果您希望變更該映射,可以提供您自己的映射。或者,您可以使用 component prop。

作為 CSS 公用程式,Typography 元件也支援所有 system 屬性。您可以將它們作為 props 直接用於元件上。

ref 會轉發到根元素。

主題預設 props

您可以使用 MuiTypography 透過主題變更此元件的預設 props。

CSS 類別

這些類別名稱對於使用 CSS 設定樣式很有用。當觸發特定狀態時,它們會應用於元件的插槽。

類別名稱規則名稱描述
.MuiTypography-alignCenteralignCenteralign="center",則套用樣式至根元素。
.MuiTypography-alignJustifyalignJustifyalign="justify",則套用樣式至根元素。
.MuiTypography-alignLeftalignLeftalign="left",則套用樣式至根元素。
.MuiTypography-alignRightalignRightalign="right",則套用樣式至根元素。
.MuiTypography-body1body1variant="body1",則套用樣式至根元素。
.MuiTypography-body2body2variant="body2",則套用樣式至根元素。
.MuiTypography-buttonbuttonvariant="button",則套用樣式至根元素。
.MuiTypography-captioncaptionvariant="caption",則套用樣式至根元素。
.MuiTypography-gutterBottomgutterBottom(下方間距)gutterBottom={true},則套用樣式至根元素。
.MuiTypography-h1h1variant="h1",則套用樣式至根元素。
.MuiTypography-h2h2variant="h2",則套用樣式至根元素。
.MuiTypography-h3h3variant="h3",則套用樣式至根元素。
.MuiTypography-h4h4variant="h4",則套用樣式至根元素。
.MuiTypography-h5h5variant="h5",則套用樣式至根元素。
.MuiTypography-h6h6variant="h6",則套用樣式至根元素。
.MuiTypography-inheritinheritvariant="inherit",則套用樣式至根元素。
.MuiTypography-noWrapnoWrap(不換行)nowrap={true},則套用樣式至根元素。
.MuiTypography-overlineoverlinevariant="overline",則套用樣式至根元素。
.MuiTypography-paragraphparagraph(段落)paragraph={true},則套用樣式至根元素。
.MuiTypography-rootroot套用樣式至根元素。
.MuiTypography-subtitle1subtitle1variant="subtitle1",則套用樣式至根元素。
.MuiTypography-subtitle2subtitle2variant="subtitle2",則套用樣式至根元素。

您可以使用下列其中一種客製化選項來覆寫元件的樣式

原始碼

如果您在此頁面中找不到資訊,請考慮查看元件的實作以取得更多詳細資訊。