css - flex容器内的绝对可滚动div没有固定高度,有可能吗?
问题描述
如何在 flex-box 内将 div 设置为可滚动(绝对)而不用固定高度填充整个视图?
(https://imgur.com/7v5OFas)(右侧部分的错字,其固定宽度,唯一期望的高度是整页)
https://codepen.io/anon/pen/oJyOOp?editors=1000 (如果我将高度添加到红色部分的相对父级,它可以工作,但我不能有固定高度。将 100% 从 html 添加到相对父母也可以,但我也不能这样做。)
目前它是:
<div style="display:flex">
<div style="flex-grow:1">
<div style="display:flex">
<div style="width:45px...">
....
</div>
<div ...header code>
....
</div>
<div style="flex-grow:1; top:70px; position: relative">
<div style="position: absolute; top:0; left:0; right:0; bottom: 0; overflow: auto>
</div>
</div>
</div>
</div>
<div style="width:45px...">
....
</div>
</div>
它最终填充了标题高度。
解决方案
如果没有必要,我会放弃绝对内容的想法,并尝试类似的东西:
html, body {
min-height: 100%;
height: 100%;
margin: 0;
}
.container{
background: blue;
display: flex;
height: 100%;
flex-flow: row;
}
.sidebar{
background: red;
height: 100%;
width: 200px;
}
.contentWrapper{
display: flex;
flex-flow: column;
flex: 1;
}
.header {
background: yellow;
height: 100px;
width: 100%;
}
.content {
flex: 1;
overflow: auto;
}
.scrollableContent {
height: 3000px;
}
<div class="container">
<div class="sidebar"></div>
<div class="contentWrapper">
<div class="header"></div>
<div class="content">
<div class="scrollableContent">
</div>
</div>
</div>
</div>
您基本上使每个容器都具有弹性,其内容的不可扩展部分将具有固定的宽度/高度,而另一部分flex: 1
则是占用其余空间的简写。
推荐阅读
- javascript - OnClick:找出点击了哪个 DOM 元素(获取路径)?
- php - 搜索匹配特定日期的 xml 数据
- unity3d - Unity 播放模式不断打开混合现实门户
- python - 打开浏览器选项卡以执行机器人框架测试用例
- python - Django:https://127.0.0.1:8000 在 Django 中不起作用
- c# - 更新操作在带有添加/编辑操作的模式弹出窗口的 Razor 页面中不起作用
- reactjs - 使用反应路由器访问客户端中的特定路由
- macos - 如何在 bash/zsh 中使用包含通配符路径的给定字符串删除一组文件?
- java - 为什么我的 hashmap 没有按时间顺序打印?
- python - 如何使用 python 检测给定模型是 keras 还是 scikit 模型?