gpt4 book ai didi

html - 如何使用 div 在底部和顶部分割屏幕,底部固定高度,顶部占用剩余空间

转载 作者:太空宇宙 更新时间:2023-11-04 15:02:59 25 4
gpt4 key购买 nike

如何使用 div 将我的 HTML 页面分成两行,其中底部 div 的高度为 100px,顶部 div 占据剩余空间。

目前我有以下内容,但是这里顶部的 div 与底部的 div 重叠:

html,
body,
object {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
div {
margin: 0px;
padding: 0px;
}
#mainContainer {
position: relative;
height: 100%;
width: 100%;
}
#topContainer {
border: 1px solid red;
position: absolute;
top: 0px;
left: 0px;
height: 100%;
width: 100%;
}
#bottomContainer {
border: 1px solid blue;
position: absolute;
bottom: 0px;
left: 0px;
height: 100px;
width: 100%;
}
<body>
<div id="mainContainer">
<div id="topContainer">
This is the top div
</div>
<div id="bottomContainer">
This is the bottom div
</div>
</div>
</body>

我试过使用 display: table;这在 Chrome 和 Firefox 中工作正常,但不幸的是在 IE9 中不工作(这是必需的)。任何帮助将不胜感激。

最佳答案

只需将#topContainer 更改为

#topContainer {
border: 1px solid red;
position: absolute;
top: 0px;
left: 0px;
bottom: 100px; //set bottom
height: calc(100% - 100); //calculate height
width: 100%;
}

您的其余代码运行良好。

这是更新的片段。

html,
body,
object {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
div {
margin: 0px;
padding: 0px;
}
#mainContainer {
position: relative;
height: 100%;
width: 100%;
}
#topContainer {
border: 1px solid red;
position: absolute;
top: 0px;
left: 0px;
bottom: 100px;
height: calc(100% - 100);
width: 100%;
}
#bottomContainer {
border: 1px solid blue;
position: absolute;
bottom: 0px;
left: 0px;
height: 100px;
width: 100%;
}
<body>
<div id="mainContainer">
<div id="topContainer">
This is the top div
</div>
<div id="bottomContainer">
This is the bottom div
</div>
</div>
</body>

关于html - 如何使用 div 在底部和顶部分割屏幕,底部固定高度,顶部占用剩余空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31692041/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com