首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法按下底部的页脚

无法按下底部的页脚
EN

Stack Overflow用户
提问于 2017-05-04 05:59:10
回答 2查看 72关注 0票数 0

我试图推动我的页脚在底部,但在我的布局,它是在顶部的部分。

这是我的密码。

样品结构

代码语言:javascript
复制
<body>
<!-- some codes here -->
<footer>
    <div id="main-footer">
        <div class="col-md-8 col-md-offset-2">
            <h1>hello world</h1>
        </div>
    </div>
</footer>
</body>

css

代码语言:javascript
复制
body {
    font-family: Helvetica, '游ゴシック', YuGothic, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'メイリオ', Meiryo, sans-serif;
    font-weight: 300;
    position: relative;

    footer {
        position: absolute;
        bottom: 0; /** no effect **/
        min-height: 500px;
        background: #000;
        width: 100%;
        z-index: 4;
        /** top: 0; -- if enabled my footer goes on the top **/
    }

}

-更新css --

代码语言:javascript
复制
html { height: 100%; }
body {
    font-family: Helvetica, '游ゴシック', YuGothic, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'メイリオ', Meiryo, sans-serif;
    font-weight: 300;
    min-height: 100%;
}

footer {
    height: 100px;
    background: red;
    z-index: 5;
    position: absolute;
    width: 100%;
    min-height: 100px;
    bottom: 0;
}

如果我将高度设置为100%,我试着检查整个身体是否会占据位置,但这是输出:

如你所见,它并没有占据我的整个页面。

EN

回答 2

Stack Overflow用户

发布于 2017-05-04 06:15:00

请使用下面的css为您的代码,可能会对您工作。

代码语言:javascript
复制
html {
    min-height:100%;
    position:relative;
    height:auto;
}

body {
    padding-bottom:500px;
}

footer {
    position: absolute;
    bottom: 0; /** no effect **/
    min-height:500px;
    background: #000;
    width: 100%;
    z-index: 4;
}
票数 1
EN

Stack Overflow用户

发布于 2017-05-04 06:18:19

正确关闭css本体大括号。也参考其他网站,并学习如何编写/编码CSS。现在,请考虑以下几点。

不要使用绝对。相反,使用相对位置。相对位置用于放置相对于其正常位置的内容的相对位置。绝对位置,用于将内容放置到最近的位置祖先。有三种立场:固定的,相对的,绝对的和静态的。

代码语言:javascript
复制
body {
    font-family: Helvetica, '游ゴシック', YuGothic, 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'メイリオ', Meiryo, sans-serif;
    font-weight: 300;
    position: relative;
}
footer {
    position: relative;
    bottom: 0; /** no effect **/
    min-height: 500px;
    background: #000;
    width: 100%;
    z-index: 4;
    /** top: 0; -- if enabled my footer goes on the top **/
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43774952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档