【发布时间】:2021-03-21 14:18:36
【问题描述】:
我正在尝试创建一个“窗口”,其中有一个“头”、“内容”和“脚”部分,所有 3 个部分中的内容可能会有所不同,我想要实现的是“头” ' 和 'foot' 扩展高度以适应它们的内容(可以是从 0px 到 300px 的任何值),并且 'content' 部分扩展以填充容器中的剩余空间。如果“内容”框的内容太大,它应该显示一个滚动条。
这是我目前所拥有的:
<style>
#container{
position: absolute;
display: table;
width: 500px;
height: calc(100vh - 80px);
top: 80px;
right: 0;
border-spacing: 10px;
background-color: lightgrey;
}
#container > .header{
position: absolute;
display: table-row;
background-color: blue;
width: calc(100% - 20px);
}
#container > .content{
position: relative;
display: table-row;
background-color: green;
}
#container > .footer{
position: absolute;
display: table-row;
background-color: red;
width: calc(100% - 20px);
bottom: 10px;
}
</style>
<div id="container">
<div class="header"> </div>
<div class="content"> </div>
<div class="footer"> </div>
</div>
最终我希望内容在页眉和页脚后面滚动,但这需要在顶部和底部的内容框中添加边距/填充,但页眉和页脚高度未知。
如果我必须借助 java 脚本来实现这一点(获取页眉和页脚的高度,然后设置内容高度),我会但更愿意使用 CSS。
【问题讨论】: