跳到内容跳到内容

AppBarAPI

React AppBar 组件的 API 参考文档。了解此导出模块的属性、CSS 和其他 API。

演示

导入

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

通过阅读本关于最小化捆绑包大小的指南,了解两者之间的区别。

属性

Paper 组件的属性也可用。

名称类型默认值描述
childrennode-

组件的内容。

classesobject-

覆盖或扩展应用于组件的样式。

有关更多详细信息,请参阅下面的 CSS 类 API

color'default'
| 'inherit'
| 'primary'
| 'secondary'
| 'transparent'
| 'error'
| 'info'
| 'success'
| 'warning'
| string
'primary'

组件的颜色。它支持默认主题颜色和自定义主题颜色,可以按照调色板自定义指南中所示的方式添加。

enableColorOnDarkboolfalse

如果为 true,则在暗黑模式下应用 color 属性。

position'absolute'
| 'fixed'
| 'relative'
| 'static'
| 'sticky'
'fixed'

定位类型。不同选项的行为在 MDN web 文档中描述。注意:sticky 并非普遍支持,在不可用时将回退到 static

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

允许定义系统覆盖以及其他 CSS 样式的系统属性。

有关更多详细信息,请参阅 `sx` 页面

ref 被转发到根元素。

继承

虽然上面没有明确记录,但 Paper 组件的属性在 AppBar 中也可用。您可以利用这一点来定位嵌套组件

主题默认属性

您可以使用 MuiAppBar 通过主题更改此组件的默认属性。

CSS 类

这些类名对于使用 CSS 进行样式设置很有用。当触发特定状态时,它们将应用于组件的插槽。

类名规则名称描述
.MuiAppBar-colorDefaultcolorDefault如果 color="default",则应用于根元素的样式。
.MuiAppBar-colorErrorcolorError如果 color="error",则应用于根元素的样式。
.MuiAppBar-colorInfocolorInfo如果 color="info",则应用于根元素的样式。
.MuiAppBar-colorInheritcolorInherit如果 color="inherit",则应用于根元素的样式。
.MuiAppBar-colorPrimarycolorPrimary如果 color="primary",则应用于根元素的样式。
.MuiAppBar-colorSecondarycolorSecondary如果 color="secondary",则应用于根元素的样式。
.MuiAppBar-colorSuccesscolorSuccess如果 color="success",则应用于根元素的样式。
.MuiAppBar-colorTransparentcolorTransparent如果 color="transparent",则应用于根元素的样式。
.MuiAppBar-colorWarningcolorWarning如果 color="warning",则应用于根元素的样式。
.MuiAppBar-positionAbsolutepositionAbsolute如果 position="absolute",则应用于根元素的样式。
.MuiAppBar-positionFixedpositionFixed如果 position="fixed",则应用于根元素的样式。
.MuiAppBar-positionRelativepositionRelative如果 position="relative",则应用于根元素的样式。
.MuiAppBar-positionStaticpositionStatic如果 position="static",则应用于根元素的样式。
.MuiAppBar-positionStickypositionSticky如果 position="sticky",则应用于根元素的样式。
.MuiAppBar-rootroot应用于根元素的样式。

您可以使用以下自定义选项之一覆盖组件的样式

源代码

如果您在此页面中没有找到信息,请考虑查看组件的实现以获取更多详细信息。