我希望在 React 中使用 Material UI 制作多个滚动列。我有一种在引导程序中使用 flex 进行的方法,但我无法将其翻译过来。我已经整理了一个 hacky 方法的演示,它需要知道你想要滚动的内容的大小(在这种情况下,AppBar)
https://codesandbox.io/s/pmly895mm
html,
body {
margin: 0;
height: 100%;
}
#root {
height: 100%;
}
.grid-container {
height: calc(100% - 64px);
}
.grid-column {
height: 100%;
overflow-y: auto;
}
在这个演示中,我将所有高度设置为 100%(html、body、#root),然后创建了两个grid-container
高度为 100% 的类 - AppBar 高度和grid-column
高度为 100% 并且溢出-y 为 auto。
在 Bootstrap 中,我会将这些类分别应用于row
和column
元素
.flex-section {
flex-grow: 1;
display: flex;
flex-direction: column;
min-height: 0;
}
.flex-col-scroll {
flex-grow: 1;
overflow: auto;
min-height: 100%;
}
元素上方的内容并不重要,因为 flex 负责处理高度。
具体来说,我希望避免这样做,height: calc(100% - 64px)
因为这需要我事先知道元素高度。我将有一些页面,我想在滚动区域上方放置一些内容,这些内容将具有动态的高内容。