css - 页眉和页脚 DIV 与中间内容重叠

标签 css html dynamic

为了让问题更容易分析,我创建了 this jsFiddle :

代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <style>
        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; }
    </style>
</head>
<body>
    <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>
</body>
</html>

对于顶部、中间和底部部分的标记,问题是:

1- 如您所见,尽管页脚 div 上有 position:absolutebottom:0px,但黑色的页脚并不真正位于页面底部

2- 更重要的是,leftSection、middleSection 和 rightSection DIV 与页眉和页脚 DIV 重叠,事实上,在这个 fiddle 中,查看 3 个中间部分显示的文本的唯一方法是放置填充以避免出现它显示在标题 DIV 下方。

我已经尝试在 middleContainer 上放置 30px 的顶部和底部值来解决重叠问题,但这并不能解决问题,我只想将 headerContainer 保持在顶部,将 footerContainer 保持在底部,同时所有 3 个中间部分都调整为100% 高度。 leftSection 和 rightSection 的宽度是固定的,而 middleSection 的宽度和高度是可变的。

最佳答案

http://jsfiddle.net/grc4/XTQuT/2/完全按照我的要求进行操作,而无需指定实体高度值。

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <style>
    body {
    margin: 0;
    height:100%;
    }
#mainContainer {
    position: absolute;
    right: 4%;
    left: 4%;
    height: 100%;
}
#headerContainer {
    width: 100%;
    position: relative;
    background: #323232;
    color: white;
    height: 30px;
}
#middleContainer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 30px 0;
}
#leftSection {
    float: left;
    width: 175px;
    background: #71ABD1;
    height: 100%;
    overflow: auto;
    color: black;
}
#middleSection {
    position: absolute;
    background-color: yellow;
    left: 175px;
    right: 175px;
    top: 0;
    bottom: 0;
    color: black;
}
#rightSection {
    float: right;
    height: 100%;
    width: 175px;
    border-left: 1px dotted black;
    background: red;
    color: black;
}
#footerContainer {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 30px;
    background: #323232;
    color: white;
}​
</style>
    </head>
    <body>
        <div id="mainContainer">
            <div id="headerContainer">
                headerContainer
            </div>
            <div id="middleContainer">
                <div id="leftSection">
                    <div style="margin-top: 30px;">leftSection</div>
                </div>
                <div id="middleSection">
                    <div style="margin-top: 30px;">middleSection</div>
                </div>
                <div id="rightSection">
                    <div style="margin-top: 30px;">rightSection</div>
                </div>
            </div>
            <div id="footerContainer">
                footerContainer
            </div>
        </div>
    </body>
    </html>

关于css - 页眉和页脚 DIV 与中间内容重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12716008/

相关文章:

html - 隐藏或显示内容的 css 媒体查询

javascript - 如何在轮播中间放置一个搜索框?

php - 在 html 中单击提交并运行 php 代码

javascript - 异步问题过滤器将不起作用,因为数组为空

html - 当内容较少时,如何将页脚放在视口(viewport)下方?

html - angular2 sm-popup 边缘的语义 ui

javascript - 在输入标签内使用 html

dynamic - 是否可以在 fsharp 中动态生成可识别联合?

python - 动态创建类 - Python

android - setOnClickListeners 用于动态创建的复选框