html - 如何在html中设置一个div来填充父元素并在子元素变大时显示滚动条?
问题描述
我是 CSS 和 HTML 的新手,并且正在尝试使用 Angular。我想要一个没有“主”滚动条(电子应用程序)的网页。
在此页面中,我将有 3 divs
。其中一个(中间的那个)将包含一个身高很大的孩子。这就是为什么这个中间div
需要用滚动条溢出。
div
换句话说,每当我调整窗口的高度时,我希望该中间成为调整后的高度。它会填满所有可用空间。
我想知道是否可以用 CSS 做到这一点?或者我是否必须编写javascript代码来设置这个中间组件的高度等于父级减去其他元素的高度?
<div>
<div>
I would like that the scroll zone expands down to the bottom of the browser
window. (this text should always be visible)
</div>
<div class="scroll-zone">
scroll-zone
<div class="big-box">big-box</div>
</div>
<div>After scroll zone (should always be visible)</div>
</div>
.scroll-zone {
height: auto; /*Do I really have to set a fixed size here ?*/
overflow: auto;
}
.big-box {
height: 1000px;
border-style: solid;
border-color: black;
}
(非工作)示例: https ://stackblitz.com/edit/angular-ivy-1szgga?file=src/app/app.component.html
解决方案
<div>
<div>
I would like that the scroll zone expands down to the bottom of the browser
window. (this text should always be visible)
</div>
<div style="max-height: 400px;overflow: auto">
scroll-zone
<div style="background-color: yellow;height: 500px">big-box</div>
</div>
<div>After scroll zone (should always be visible)</div>
</div>
推荐阅读
- nginx - nginx 401 问题背后的 JForg Artifactory 7.x
- ios - Swift API URLSession 不会将字符串附加到我的本地字符串数组
- awk - 替换字符串并在同一字段的某个位置插入一个字符
- operating-system - 内存访问安全实现问题
- arrays - 更改 2D numpy 数组的子集
- ruby - 如何按字符串搜索数组[在红宝石中]
- python - 在 Python 中将字符串转换为整数
- json.net - 如何在 Blazor WebAssemby 应用程序中实现 System.Text.Json.Serialization.ReferenceHandler.Preserve
- swift - 无法将“OSLogMessage”类型的值转换为预期的字典键类型“AnyHashable”
- javascript - vscode:如何获取文档中光标的位置?