0

我有一个没有看到解决方案的案例。这是我的问题:

我有一个包含三个部分(页眉、部分和页脚)的页面,页脚必须始终与底部齐平。部分部分应该占据页眉和页脚之间的所有可用位置,但必须有一个根据页面不同的最小高度(我将在 CSS 上手动设置)。

当达到最小高度时,应该可以在整个页面上滚动。

这是我用来设置页眉、节和页脚的代码示例,占据所有可用位置。

CSS

body {
    margin: 0
}
header, section, footer {
    left:0;
    right:0;
    overflow: hidden;
    position: absolute;
}
header {
    height: 70px;
    top: 0;
    background-color: green;
}
section {
    top: 70px;
    bottom: 195px;
    background-color: gray;
    min-height:300px;
}
article {
    overflow: hidden;
    background-color:lightyellow;
}
.news {
    position: absolute;
    bottom: -30px;
    width: 100%;
    background-color: lime;
}
footer {
    height: 195px;
    bottom: 0;
    background-color: pink;
}

HTML

<header>
    <div class="container">
        <h2>My header</h2>
    </div>
</header> 
<section>
    <article>
        <div class="news">
            <div class="row-fluid">
                <a href="#">UP</a>
            </div>
            <div class="row-fluid">
                <div class="container">
                    <div class="span6">News 1</div>
                    <div class="span6">News 2</div>
                </div>
            </div>
        </div>
    </article>
</section> 
<footer>
    <div class="container">
    My footer
</div>
</footer>​

一个 jsfiddle 可用于示例:http: //jsfiddle.net/Nk6uY/

编辑

如何在我的部分上添加一个最小高度,当它到达时,我的窗口上会出现一个滚动条?

编辑 2

我将添加有关我的问题的更多信息。首先,我在 section 标签内的大部分内容都将设置为绝对值。并隐藏一些并出现在动作中(主要是javascript)。出于这个原因,我知道如果有人点击链接,我需要查看所有内容的每个部分的最小高度。

对于我的示例,div 新闻是隐藏的,当您单击它时,它至少需要 360 像素才能可见。但是,如果我的窗口比这个小,我的窗口上就没有滚动条,并且我的所有内容都被页脚覆盖。

4

1 回答 1

0

You can only achieve this through javascript - you would need to give your header, section and footer ids and then use something like this:

function ResizeBody() {
    var header = document.getElementById("Header");
    var section = document.getElementById("Section");
    var footer = document.getElementById("Footer");

    var height = GetBodyHeight() - header.offsetHeight - footer.offsetHeight - anyPaddingToTopOrBottomOfThreeMainSections;
    if (height > 0) {
         body.style.height = height + "px";
    }
}

function GetBodyHeight() {
    if (window.innerHeight > 0) {
        return window.innerHeight;
    }
    else {
        return document.documentElement.clientHeight;
    }
}

window.onresize = function () {
    ResizeBody();
};


$(document).ready(function () {
    ResizeBody();
});

UPDATE

Sorry, I think i read the question wrong - do you want the section to grow to the screen size or are you manually going to set it the if there is too much content have a scroll bar?

in which case you should just set the height (not as a min height) of the section and instead of overflow:hidden use overflow:scroll;

于 2012-12-12T09:21:10.570 回答