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

问题描述 投票:5回答:1

我有一个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>

在第一个自举列后,另一个"col-sm-4"跟随,然后是"col-sm-2"。按钮位于GridList

这是一个视觉

enter image description here

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

有任何想法吗?

html css reactjs material-ui
1个回答
5
投票

Material-UI文档称之为clipped under the app bar的抽屉。要实现它,首先必须为你的z-index对象定义一个AppBar

styles

然后将其应用于const styles = theme => ({ appBar: { // Make the app bar z-index always one more than the drawer z-index zIndex: theme.zIndex.drawer + 1, }, }); 组件:

AppBar

由于您的抽屉现在位于<AppBar position="absolute" className={classes.appBar}> 下方,您需要将抽屉中的内容移动到屏幕下方,以便它不会隐藏在栏下方。你可以用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, }); 添加为抽屉中的第一个内容:

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> 样式将从当前toolbar加载有关应用栏高度的信息,然后调整theme的大小,以确保内容不会被应用栏隐藏。

你可以找到一个完整的代码示例div

© www.soinside.com 2019 - 2024. All rights reserved.