html - 如何让HTML页面占满高度?

标签 html css footer

<分区>

Possible Duplicate:
How to make the web page height to fit screen height

我有一个没有占据整个屏幕的 HTML 页面。它只占用 HTML 内容的大小,页脚不在页面末尾(它应该在末尾)

我该如何解决?

我只需要页脚位于页面末尾。

我的 HTML 结构如下:

<body>
    <div id="app">
        <!-- Header -->
        <div id="header"></div>
        <!-- Hero container -->
        <div class="container">
            <!-- Sub container -->
            <div class="container"></div>
        </div>
        <!-- Footer -->
        <div id='footer'></div>
    </div>
</body>

我的 CSS 如下:

html {
    height: 100%;
}

body {
    color: hsl(0, 0%, 33%);
    font-family: Helvetica, Arial, sans-serif;
    font-size: 13px;
    line-height: 1;
    background: none repeat scroll 0 0 hsl(0, 0%, 98%);
    margin: 0;
    padding: 0;
    height: 100%;
}

* {
    outline: 0 none;
}

#app {
    min-height: 100%;
    margin:auto;
    width: 100%;
}

div,span,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,a,big,cite,code,del,dfn,em,img,small,strike,strong,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tr,th,td,embed,menu,nav
    {
    border: 0 none;
    font: inherit;
    margin: 0;
    padding: 0;
    vertical-align: baseline;
}

.container {
    margin: 0 auto;
    position: relative;
    width: 990px;
}

#footer {
    margin: 100px 0 0;
}

谁能指导我。我是 CSS 的新手。 :( 卡坏了!:(

编辑

会不会是因为我在 body 的一些 div 元素中有 float ?

编辑2

奇怪的是,即使页面很长并且我向下滚动,在页脚之后也有一小条永远不会消失的空白。 当我尝试使用 Firebug 选择空白区域时,它会将我显示为元素。

最佳答案

一种方法是使用 Jquery 将应用程序 div 的最小高度设置为屏幕的高度,这意味着如果内容没有填满屏幕,它仍会填满该高度。 像这样的事情可能会成功:

$(文档).ready(函数() {

var screenHeight = $(document).height();

$('#app').css('最小高度', screenHeight);

});

关于html - 如何让HTML页面占满高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13477169/

上一篇:移动浏览器上的 CSS 固定位置

下一篇:css - 如何垂直对齐div中的图像?

相关文章:

html - IE9 和固定位置

javascript - 客户端如何存储动态图像

javascript - 添加 onClick 事件以在 D3.js 中的每个栏上方显示一个隐藏的 div(也许我还缺少重要的 css 代码?)

css - 为内部元素设置 CSS 样式

html - Bootstrap 字形图标上的链接

html - 页脚不显示?

CSS 高度问题 - 容器无法拉伸(stretch)(无 float )

html - 将页脚放在底部?

javascript - 事件导航按钮中的不同颜色

html - 在同一行上对齐文本而不 float