【问题标题】:How to make footer stick to bottom despite size of content?尽管内容大小,如何使页脚粘在底部?
【发布时间】:2014-11-23 03:34:06
【问题描述】:

我有这个 CSS 代码:

#main-wrapper {min-height: 300px;}

#main {}

.clearfix:after {content:".";display:block;height:0;clear:both;visibility:hidden;}

我试过了:clear:both;底部:0;位置:固定;宽度:100%;对于页脚..

但它只适用于短内容显示..当页面内容太长时,我必须向下滚动页面到页脚..

请帮忙

【问题讨论】:

标签: css footer sticky-footer


【解决方案1】:

一个更简单更整洁的方法:

HTML

<div id="main-wrapper">
    <div id="content">Main content</div>
    <footer>Footer content</footer>
</div>

CSS

#content {
    min-height: 50vh; /*adjust to find the one that suits your content*/
}

【讨论】:

    【解决方案2】:

    see the example code here

    HTML

    <div id="main-wrapper">
        <div id="content"> content of any length</div>
        <div id="footer">Footer</div>
    </div>
    

    CSS

    * {
        padding: 0;
        margin: 0;
    }
    #content {
        margin-bottom: 30px;/*same as footer height*/
    }
    #footer{
        position: fixed;
        bottom:0;
        height: 30px;
        background: #eee;
        width: 100%;
        text-align: center;
    }
    

    【讨论】:

    • 即使内容溢出屏幕,页脚也会一直粘在底部
    猜你喜欢
    • 2016-07-11
    • 2016-04-07
    • 2023-04-01
    • 2013-09-26
    • 2018-09-10
    • 2013-01-18
    • 1970-01-01
    • 2017-06-29
    相关资源
    最近更新 更多