【发布时间】:2019-01-20 08:39:56
【问题描述】:
面对一些嵌套的flex-boxes,我卡住了,无法正确滚动内容。这是我的CSS:
html,body,#root{
width:100%;
height:100%;
padding:0;
margin:0;
}
.flex-fill{
height:100%;
width:100%;
display:flex;
align-items:stretch;
}
.flex-fill>div:last-child{
flex-grow:1;
}
.flex-col{
flex-direction:column;
}
<div id='root'>
<div class='flex-fill flex-col'><!--actually scrolling div-->
<div style="flex:0 0 35px"><h1>main title</h1></div>
<div>
<div class='flex-fill flex-col'>
<div style="flex:0 0 30px"><h2>subtitle</h2></div>
<div class='flex-fill'>
<div style="flex:0 0 30%">...left side nav list...</div>
<div class='flex-fill flex-col'>
<div style="flex:0 0 25px">...data header...</div>
<!--I hope the content of this div is scroll-able-->
<div style="overflow-y:scroll">...data list...</div>
</div>
</div>
</div>
</div>
</div>
</div>
最里面的 div 中包含的数据列表很长,我想让它可以滚动。但事实上,上面的代码使根 div 的全部内容滚动。我对 flex 或 overflow 有误解吗?如何修复其他部分并滚动数据列表?
【问题讨论】:
-
/*这些应该是 cmets*/?如果是这样,HTML 会像这样 完成。无论如何,从我在这里看到的情况来看,它不会滚动,因为它可以放大到显示内容所需的大小。例如,将
max-height: 50px;添加到要滚动的div中,如果内容高于50px,则需要滚动。 -
对不起,我犯了错误。我在这里手动输入代码,将 /**/ 作为理所当然的注释。实际代码中没有这样的东西。真正的代码是用 React 编写的,而且很长。我将在浏览器中再次检查最终代码并修改我的问题。
-
我不能将高度,即 50px 应用到数据列表容器 div,我希望它占据整个剩余空间。
标签: css scroll flexbox overflow