You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Material UI永久侧边栏遮挡导航栏且样式不生效问题求助

Material UI永久侧边栏遮挡导航栏且样式不生效问题求助

各位大佬好,我遇到个Material UI的问题折腾半天没解决,来求支招!

我设置的Drawer组件完全不遵守指定的样式规则:一方面它的宽度不是我设定的17rem,另一方面还超出了父组件的边界;更头疼的是它还把顶部的AppBar给挡住了,我特意给AppBar加了zIndex属性,似乎也没起作用。

下面是我项目里相关的代码片段:

const styles = {
  background: {
    display: 'flex',
    //flexDirection: 'row',
    height: '100vh',
    width: '100vw',
    backgroundColor: '#303030',
  },
  drawer: {
    width: '17rem',
  },
  toolbar: {
    justifyContent: 'space-between',
  },
  titles: {
    display: 'flex',
    alignItems: 'center',
    cursor: 'pointer',
  },
  btn: {
    color: 'inherit',
    outline: 'none',
    fontWeight: 500,
  },
}

function App() {
  return (
    <>
      <AppBar style={{ position: 'relative', zIndex: '1201' }}>
        <Toolbar style={styles.toolbar}>
          <div style={styles.titles}>
            <Typography variant='h5'>
              Naughty pie
            </Typography>
            {/* 此处省略部分内容 */}
          </div>
        </Toolbar>
      </AppBar>
      {/* Drawer组件的代码应该在这里,原提问中未完全展示 */}
    </>
  )
}

有没有大佬能帮我看看这是哪里出问题啦?

备注:内容来源于stack exchange,提问作者pauk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 11:19:31