material-ui - 试图让 Material-UI 剪辑抽屉在 flex 布局中工作
问题描述
我从裁剪的抽屉示例代码开始,并尝试围绕它进行构建。在样本中插入组件时(即,将'{'你认为水移动得很快?你应该看到冰块。'} 用其他内容代替),内容受抽屉高度的限制。当尝试在 sample 之外插入内容时,一切都从抽屉下方开始。
预期行为:能够将内容放置在抽屉周围的任何位置。根据抽屉菜单选择,我有不同的组件隐藏/变得可见
我最初从永久抽屉示例开始,一切正常,除了我需要将抽屉放在应用栏下方。
解决方案
布局由一个包含Drawer
主要内容区域的 flex 容器组成。内容区域 ( .appContent
) 扩展以填充抽屉右侧(或左侧)的空间。您的所有内容都应放置在此元素内。
更新:修复了适用于 IE 11 的样式
基本结构:
<div className={classes.root}>
<AppBar position="fixed" className={classes.appBar} />
<Drawer
variant="permanent"
className={classes.drawer}
classes={{ paper: classes.drawerPaper }}
/>
<main className={classes.appContent}>
{/* Page content goes here */}
</main>
</div>
款式
const styles = theme => ({
// The main flex container for the app's layout. Its min-height
// is set to `100vh` so it always fill the height of the screen.
root: {
display: "flex",
minHeight: "100vh",
zIndex: 1,
position: "relative",
overflow: "hidden",
},
appBar: {
zIndex: theme.zIndex.drawer + 1
},
// Styles for the root `div` element in the `Drawer` component.
drawer: {
width: theme.layout.drawerWidth
},
// Styles for the `Paper` component rendered by `Drawer`.
drawerPaper: {
width: "inherit",
paddingTop: 64 // equal to AppBar height (on desktop)
},
// Styles for the content area. It fills the available space
// in the flex container to the right (or left) of the drawer.
appContent: theme.mixins.gutters({
// https://github.com/philipwalton/flexbugs#flexbug-17
flex: '1 1 100%', // Updated to fix IE 11 issue
maxWidth: "100%",
paddingTop: 80, // equal to AppBar height + 16px
margin: '0 auto',
// Set the max content width for large screens
[theme.breakpoints.up('lg')]: {
maxWidth: theme.breakpoints.values.lg,
},
})
现场示例(codesandbox)
推荐阅读
- java - Thymeleaf 模型与 HttpServletRequest
- swift - UITableview 单元格高度在 iOS 14.0 中的滚动表视图上发生变化
- javascript - 如何查看在网页上单击按钮时正在发生的过程?
- vb.net - 使用 vb.net 以编程方式为系统范围的“访问权限”添加或删除用户
- visual-c++ - 将此代码转换为宏
- python - pip wheel 如何解决传递依赖?
- sql - 按字段部分分组
- python - 我可以用什么代替 strip() 来删除 \n、\t 和空格?
- angular - 在 Angular 7 中使用 npm run build 命令时,如何在正文末尾的 index.html 中添加自定义脚本?
- python-3.x - 如何使用python从xml文件中动态获取数据?