材质UI抽屉不会在Appbar下移动

Cla*_*013 5 html css reactjs material-ui

我有一个Appbar和它下面的抽屉.在这两个组件下我有3个divs带引导程序,每个组件div都有一组按钮.

问题是抽屉覆盖了Appbar,我似乎无法移动它.

这是我的代码:

<div className="App">

        <AppBar position="static">
          <Toolbar>
              <IconButton color="inherit" aria-label="Menu">
                <MenuIcon />
              </IconButton>
              <Typography variant="title" color="inherit" aria-label="Menu">
                title
              </Typography>
          </Toolbar>
        </AppBar>

        <Drawer
          variant="permanent"
          style={{width: '100%', zIndex: '1400', position:'absolute'}}
        >
          <Button>1</Button>
          <Button>2</Button>
          <Divider />
          <Button>1</Button>
          <Button>2</Button>
        </Drawer>
        <br />
        <div className="container-full">
          <div className="row">
            <div class="col-sm-6">  
              <GridList cellHeight={50} className={styles.gridList} cols={5}>

                <Button style={{width: '150px', border: '1px solid'}} variant="raised" color="primary">
                  <div 
                  style={{fontSize:'12px', display: 'flex', justifyContent: 'center', textAlign:'center'}}>
                    Mohnweckerl Wiener Gouda
                  </div>
                </Button>
Run Code Online (Sandbox Code Playgroud)

在第一个bootstrap列之后,另一个"col-sm-4"跟随然后a "col-sm-2".按钮在一个GridList

这是一个视觉

在此输入图像描述

抽屉应该从箭头相遇的地方开始.

有任何想法吗?

Jul*_*ont 6

Material-UI文档将其称为已被裁剪到应用栏下方的抽屉。要实现它,首先必须z-index为您AppBarstyles对象定义一个:

const styles = theme => ({
  appBar: {
    // Make the app bar z-index always one more than the drawer z-index
    zIndex: theme.zIndex.drawer + 1,
  },
});
Run Code Online (Sandbox Code Playgroud)

然后将其应用于AppBar组件:

<AppBar position="absolute" className={classes.appBar}>
Run Code Online (Sandbox Code Playgroud)

由于您的抽屉现在位于的下方AppBar,因此您需要将抽屉中的内容向下移动到屏幕下方,以使其不会隐藏在栏的下方。您可以使用完成此操作theme.mixins.toolbar。首先,添加toolbar样式:

const styles = theme => ({
  appBar: {
    zIndex: theme.zIndex.drawer + 1,
  },
  // Loads information about the app bar, including app bar height
  toolbar: theme.mixins.toolbar,
});
Run Code Online (Sandbox Code Playgroud)

然后,将以下div内容添加为抽屉中的第一部分内容:

<Drawer>
  // Make sure this div is the first piece of content in your drawer
  <div className={classes.toolbar} />

  // Put your other drawer content here like you normally would
</Drawer>
Run Code Online (Sandbox Code Playgroud)

toolbar风格将装载大约从目前的应用栏高度信息theme,然后大小div,这样可以确保内容不会被通过应用栏隐藏。

您可以在此处找到完整的代码示例。