html - 带液体容器的粘性页脚

标签 html css footer liquid sticky

你好,有人知道我如何构建一个液体内容容器,让页脚卡在底部而不与内容 div 重叠并且不使用 Java 脚本吗?

我正在使用 Matthew James Taylor 的粘性页脚,这是一个很好的解决方案,但不是我使用的布局。

当我将内容 div #body 设置为 min-height: 100%;然后它与页脚重叠。使用最小高度时 min-height: 700px;那么它不是液体。有谁知道我该如何解决这个问题?

html,
body {
    margin:0;
    padding:0;
    height:100%;
}
#container {
    min-height:100%;
    position:relative;
}
#header {
    background:#ff0;
    padding:10px;
}
#body {
    padding:10px;
    padding-bottom:60px;    /* Height of the footer */

    position: absolute;
    min-height: 700px;

    width: 800px;
    background: #ccc;
    margin: auto;

}
#footer {
    position:absolute;
    bottom:0;
    width:100%;
    height:60px;            /* Height of the footer */
    background:#6cf;
}
/* other non-essential CSS */
#header p,
#header h1 {
    margin:0;
    padding:10px 0 0 10px;
}
#footer p {
    margin:0;
    padding:10px;
}
</style>
<!--[if lt IE 7]>
<style media="screen" type="text/css">
#container {
    height:100%;
}
</style>
<![endif]-->



<div id="container">   
    <div id="header"></div>
    <div id="body"></div>
    <div id="footer"></div>
</div>

额外的

我尝试了一种新方法,但现在大量内容从 div 中流出。我已经尝试过 clearfix,但它不起作用。

<style type="text/css">
    * {
        margin: 0;
        padding: 0;
    }

    body, html {
        height: 100%;
    }

    #container {
        background: #000;
        width: 700px;
        margin: 0 auto;
        position: relative;
        height: auto !important;
        min-height: 100%;
        height: 100%;
    }

    #content {
        padding-bottom: 100px;
    }

    #footer {
        position: absolute;
        left: 0;
        bottom: 0;
        height: 100px;
        width: 100%;
        background: #0f0;
    }
    #header {
        position: absolute;
        left: 0;
        top: 0;
        height: 100px;
        width: 100%;
        background: #0f0;
    }

    #inner {
        position: absolute;
        top: 100px;
        bottom: 120px;
        left: 0px;
        width: 100%;
        background-color: #9BC9D1;
    }
    .clearfix:before,
    .clearfix:after {
        content: " "; /* 1 */
        display: table; /* 2 */
    }

    .clearfix:after {
        clear: both;
    }

    /*
     * For IE 6/7 only
     * Include this rule to trigger hasLayout and contain floats.
     */

    .clearfix {
        *zoom: 1;
    }
</style>

HTML

<div id="container">
    <div id="header">
        Header
    </div>
                <div id="content" >







            <div id="inner">
                Content<br>
                Content<br>

                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>

                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>
                Content<br>


            </div>



                </div>
    <div id="footer">
        Footer here
    </div>        
</div>

最佳答案

纯 CSS 解决方案可能适用于初始页面加载,但当用户调整页面大小时,页脚将移动。我建议使用 jQuery。该策略是定义一个函数,并在加载 DOM 和触发 .resize() 事件时调用它。

关于html - 带液体容器的粘性页脚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18802902/

相关文章:

css - 使用自定义页面时,wordpress 页脚移动到主要内容的顶部

html - 强制按钮显示在内容下方 IE7

html - 每行最多 3 个 div,即使只有 1 或 2 个 div,Flexbox 的宽度也相同

html - 垂直居中的元素在顶部留下空白空间

javascript - 某些 CSS 模块样式未应用

Android ListView Footer View 未放置在屏幕底部

html - 布局中的CSS背景

html - 媒体查询不适用于响应式设计

javascript - 比较两个页面的内容

html - 页脚不在页面底部,而是在背景图像的底部