中心网站内容没有重叠标题和&页脚

时间:2012-11-23 11:03:47

标签: html css

我有一个基本的网站结构,包含页眉,页脚和内容区域。 我可以找到的几乎所有解决方案都集中在页面内容中使用CSS绝对定位,设置内容div的边距,并使其浮动在浏览器窗口的中心。 然而,当窗口尺寸减小时,这导致覆盖页眉和/或页脚的内容。 相反,我希望页面在无法放入窗口时滚动。

以下是该页面的屏幕截图: layout -- area with red border should be vertically centered

红色边框区域应垂直居中,不覆盖任何其他元素。

以下是我正在使用的HTML& CSS:

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Layout Test</title>
</head>

<body>
    <div class="wrapper">
        <div class="header">Header Content</div>
        <div class="articleContainer">
            <div class="articleLeft">
                <div class="articleTitle">
                    <h1 class="articleTitle">Title</h1>
                </div>
                <div class="articleText">
                    <p>Lorem ipsum ...</p>
                </div>
            </div>
            <div class="articleRight">
                <div class="articleImage"></div>
            </div>
            <div class="stepper">Stepper</div>
        </div>
        <div class="push"></div>
    </div>
    <div class="footer">Footer Content</div>
</body>
</html>

CSS:

@charset "UTF-8";


* {
    margin: 0;
}

html, body {
    height: 100%;
}

.wrapper {
    min-height: 100%;
    height: auto !important;
    height: 100%;
    margin: 0 auto -48px;
}
.header {
    text-align: center;
    background-color: #7FF152;
    height: 48px;
}

.articleContainer {
    background-color: #CCFFFF;
    margin-right: auto;
    margin-left: auto;
    width: 700px;
    clear: both;
    min-height: 240px;
    position: relative;
    border: medium solid #FF0000;
}

.articleLeft {
    float: left;
    height: 450px;
    width: 330px;
}

.articleTitle {
    text-align: center;
    margin: 20px;
}

.articleText {
    max-height: 350px;
    overflow: auto;
}

.articleRight {
    float: right;
    height: 450px;
    width: 330px;
    background: url(articleImage.fw.png) no-repeat center center;
}

.stepper {
    clear: both;
    text-align: center;
    background-color: #FFFF00;
}

.footer {
    background-color: #CC6633;
    text-align: center;
    height: 48px;
}

.footer, .push {
    height: 48px; /* .push must be the same height as .footer */
}

我已将两者都上传到此处:http://cl.ly/3f2o1v0U2c0k

这是jsfiddle:http://jsfiddle.net/gudmN/1/

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

1)将margin: 0 auto; height: auto; float: left添加到.articlecontainer 2)制作页眉和页脚float: left; width: 100%; height: 48px

相关问题