跳到主要內容
+

屬性

此 API 頁面列出了所有自訂 MUI 系統屬性、它們如何與主題連結,以及它們計算出的 CSS 屬性。

雖然此頁面記錄了自訂屬性,但 MUI 系統被設計為 CSS 的超集,因此也支援所有其他常規 CSS 屬性和選擇器。

屬性參考表

請注意,此表僅列出自訂屬性。所有其他常規 CSS 屬性和選擇器也受支援。您可以查看下面的圖例

系統鍵 CSS 屬性 系統樣式函式 主題映射
border border border ${value}px solid
borderBottom border-bottom borderBottom ${value}px solid
borderColor border-color borderColor theme.palette[value]
borderLeft border-left borderLeft ${value}px solid
borderRadius border-radius borderRadius theme.shape.borderRadius * value
borderRight border-right borderRight ${value}px solid
borderTop border-top borderTop ${value}px solid
boxShadow box-shadow boxShadow theme.shadows[value]
displayPrint display displayPrint none
display display displayRaw none
alignContent align-content alignContent none
alignItems align-items alignItems none
alignSelf align-self alignSelf none
flex flex flex none
flexDirection flex-direction flexDirection none
flexGrow flex-grow flexGrow none
flexShrink flex-shrink flexShrink none
flexWrap flex-wrap flexWrap none
justifyContent justify-content justifyContent none
order order order none
gap gap gap theme.spacing(value)
columnGap column-gap columnGap theme.spacing(value)
rowGap row-gap rowGap theme.spacing(value)
gridColumn grid-column gridColumn none
gridRow grid-row gridRow none
gridAutoFlow grid-auto-flow gridAutoFlow none
gridAutoColumns grid-auto-columns gridAutoColumns none
gridAutoRows grid-auto-rows gridAutoRows none
gridTemplateColumns grid-template-columns gridTemplateColumns none
gridTemplateRows grid-template-rows gridTemplateRows none
gridTemplateAreas grid-template-areas gridTemplateAreas none
gridArea grid-area gridArea none
bgcolor background-color bgcolor theme.palette[value]
color color color theme.palette[value]
bottom bottom bottom none
left left left none
position position position none
right right right none
top top top none
zIndex z-index zIndex theme.zIndex[value]
height height height none
maxHeight max-height maxHeight none
maxWidth max-width maxWidth none
minHeight min-height minHeight none
minWidth min-width minWidth none
width width width none
boxSizing box-sizing boxSizing none
mmargin margin 間距 theme.spacing(value)
mbmarginBottom margin-bottom 間距 theme.spacing(value)
mlmarginLeft margin-left 間距 theme.spacing(value)
mrmarginRight margin-right 間距 theme.spacing(value)
mtmarginTop margin-top 間距 theme.spacing(value)
mxmarginX margin-leftmargin-right 間距 theme.spacing(value)
mymarginY margin-topmargin-bottom 間距 theme.spacing(value)
marginInline margin-inline 間距 theme.spacing(value)
marginInlineStart margin-inline-start 間距 theme.spacing(value)
marginInlineEnd margin-inline-end 間距 theme.spacing(value)
marginBlock margin-block 間距 theme.spacing(value)
marginBlockStart margin-block-start 間距 theme.spacing(value)
marginBlockEnd margin-block-end 間距 theme.spacing(value)
ppadding padding 間距 theme.spacing(value)
pbpaddingBottom padding-bottom 間距 theme.spacing(value)
plpaddingLeft padding-left 間距 theme.spacing(value)
prpaddingRight padding-right 間距 theme.spacing(value)
ptpaddingTop padding-top 間距 theme.spacing(value)
pxpaddingX padding-leftpadding-right 間距 theme.spacing(value)
pypaddingY padding-toppadding-bottom 間距 theme.spacing(value)
paddingInline padding-inline 間距 theme.spacing(value)
paddingInlineStart padding-inline-start 間距 theme.spacing(value)
paddingInlineEnd padding-inline-end 間距 theme.spacing(value)
paddingBlock padding-block 間距 theme.spacing(value)
paddingBlockStart padding-block-start 間距 theme.spacing(value)
paddingBlockEnd padding-block-end 間距 theme.spacing(value)
排版 font-familyfont-weightfont-sizeline-heightletter-spacingtext-transform 排版 theme.typography[value]
fontFamily font-family fontFamily theme.typography[value]
fontSize font-size fontSize theme.typography[value]
fontStyle font-style fontStyle theme.typography[value]
fontWeight font-weight fontWeight theme.typography[value]
letterSpacing letter-spacing letterSpacing theme.typography[value]
lineHeight line-height lineHeight theme.typography[value]
textAlign text-align textAlign none

圖例

讓我們從上面的表格中取一行,例如

系統鍵 CSS 屬性 系統樣式函式 主題映射
mbmarginBottom margin-bottom 間距 theme.spacing(value)

並詳細說明每一欄

  • 系統鍵。此欄列出了您可以使用 sx 屬性(或作為系統函式)使用此屬性的鍵。

    <Button sx={{ mb: 3 }}>
    // or
    <Box mb={3}>
    // or
    <Box marginBottom={3}>
    
  • CSS 屬性。此欄描述了使用此系統屬性時將產生的 CSS 屬性。

    .my-class {
      margin-bottom: Xpx;
    }
    
  • 系統樣式函式。此欄列出了生成其他欄中顯示的屬性的函式,以供您在想要將此功能新增到您的自訂元件時參考。這些函式可以從 @mui/system 匯入。您可以在自訂元件頁面上看到使用樣式函式的範例。內容連結到描述這些屬性的文件頁面;在此範例中,為間距頁面。

  • 主題映射。最後,此欄告訴您此屬性如何與主題連結 - 在此範例中,您提供的任何值都將用作 theme.spacing 輔助函式的輸入。

讓我們來看一個範例

<Button sx={{ mb: 3 }} />

// is equivalent to
<Button sx={{ marginBottom: theme => theme.spacing(3)}} />

由於預設主題間距為 8px,這將產生以下 CSS 類別

.my-class {
  margin-bottom: 24px;
}