这是我试图制作的 fiddle 来解决这个问题: http://jsfiddle.net/BPJxD/1/
对于顶部、中间和底部部分的标记,问题是:
1- 正如您所看到的,尽管页脚 div 上有 position:absolute 和 bottom:0px,但黑色的页脚并不真正位于页面底部
2- 更重要的是,leftSection、middleSection 和 rightSection DIV 与页眉和页脚 DIV 重叠,事实上,在这个 fiddle 中,查看 3 个中间部分显示的文本的唯一方法是放置填充以避免出现它显示在标题 DIV 下方。
我已经尝试在 middleContainer 上放置 30px 的顶部和底部值来解决重叠问题,但这并不能解决问题,我只想将 headerContainer 保持在顶部,将 footerContainer 保持在底部,同时所有 3 个中间部分都调整为100% 高度。 leftSection 和 rightSection 的宽度是固定的,而 middleSection 的宽度和高度是可变的。
body {
margin: 0;
}
#mainContainer {
position: absolute;
right: 4%;
left: 4%;
height: 100%;
}
#headerContainer {
width: 100%;
z-index: 10;
position: absolute;
background: #323232;
color: white;
height: 30px;
}
#middleContainer {
height: 100%;
}
#leftSection {
position: absolute;
float: left;
width: 175px;
background: #71ABD1;
height: 100%;
overflow: auto;
color: black;
padding-top: 30px;
}
#middleSection {
position: absolute;
height: 100%;
background-color: yellow;
left: 175px;
right: 175px;
color: black;
padding-top: 30px;
}
#rightSection {
float: right;
height: 100%;
width: 175px;
border-left: 1px dotted black;
background: red;
color: black;
padding-top: 30px;
}
#footerContainer {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: #323232;
color: white;
}
<div id="mainContainer">
<div id="headerContainer">
headerContainer
</div>
<div id="middleContainer">
<div id="leftSection">
leftSection
</div>
<div id="middleSection">
middleSection
</div>
<div id="rightSection">
rightSection
</div>
</div>
<div id="footerContainer">
footerContainer
</div>
</div>
最佳答案
你所有的 div 都是 padding-top 30px 和 100% - 这使得容器 100%+30px 高
尝试
height: calc(100% - 30px);
body {
margin: 0;
}
#mainContainer {
position: absolute;
right: 4%;
left: 4%;
height: 100%;
}
#headerContainer {
width: 100%;
z-index: 10;
position: absolute;
background: #323232;
color: white;
height: 30px;
}
#middleContainer {
height: 100%;
}
#leftSection {
position: absolute;
float: left;
width: 175px;
background: #71ABD1;
height: calc(100% - 30px);
overflow: auto;
color: black;
padding-top: 30px;
}
#middleSection {
position: absolute;
height: calc(100% - 30px);
background-color: yellow;
left: 175px;
right: 175px;
color: black;
padding-top: 30px;
}
#rightSection {
float: right;
height: calc(100% - 30px);
width: 175px;
border-left: 1px dotted black;
background: red;
color: black;
padding-top: 30px;
}
#footerContainer {
position: absolute;
bottom: 0;
width: 100%;
height: 30px;
background: #323232;
color: white;
}
<div id="mainContainer">
<div id="headerContainer">
headerContainer
</div>
<div id="middleContainer">
<div id="leftSection">
leftSection
</div>
<div id="middleSection">
middleSection
</div>
<div id="rightSection">
rightSection
</div>
</div>
<div id="footerContainer">
footerContainer
</div>
</div>
关于html - 使用页眉和页脚 div 重叠中间内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56149315/