跳到内容
+

属性

此 API 页面列出了所有自定义 MUI System 属性,它们如何与主题关联,以及它们计算出的 CSS 属性。

虽然此页面记录了自定义属性,但 MUI System 被设计为 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
m, margin margin spacing theme.spacing(value)
mb, marginBottom margin-bottom spacing theme.spacing(value)
ml, marginLeft margin-left spacing theme.spacing(value)
mr, marginRight margin-right spacing theme.spacing(value)
mt, marginTop margin-top spacing theme.spacing(value)
mx, marginX margin-left, margin-right spacing theme.spacing(value)
my, marginY margin-top, margin-bottom spacing theme.spacing(value)
marginInline margin-inline spacing theme.spacing(value)
marginInlineStart margin-inline-start spacing theme.spacing(value)
marginInlineEnd margin-inline-end spacing theme.spacing(value)
marginBlock margin-block spacing theme.spacing(value)
marginBlockStart margin-block-start spacing theme.spacing(value)
marginBlockEnd margin-block-end spacing theme.spacing(value)
p, padding padding spacing theme.spacing(value)
pb, paddingBottom padding-bottom spacing theme.spacing(value)
pl, paddingLeft padding-left spacing theme.spacing(value)
pr, paddingRight padding-right spacing theme.spacing(value)
pt, paddingTop padding-top spacing theme.spacing(value)
px, paddingX padding-left, padding-right spacing theme.spacing(value)
py, paddingY padding-top, padding-bottom spacing theme.spacing(value)
paddingInline padding-inline spacing theme.spacing(value)
paddingInlineStart padding-inline-start spacing theme.spacing(value)
paddingInlineEnd padding-inline-end spacing theme.spacing(value)
paddingBlock padding-block spacing theme.spacing(value)
paddingBlockStart padding-block-start spacing theme.spacing(value)
paddingBlockEnd padding-block-end spacing theme.spacing(value)
排版 font-family, font-weight, font-size, line-height, letter-spacing, text-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 属性 系统样式函数 主题映射
mb, marginBottom margin-bottom spacing theme.spacing(value)

并详细说明每一列

  • 系统键。此列列出了您可以通过哪些键使用 sx prop(或作为系统函数)来使用此属性。

    <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;
}