简体   繁体   English

将div扩展到页面底部不起作用

[英]Extending div to bottom of page not working

I have been trying to fix the length of this div for awhile, and I'm sure it is something completely simple, just not seeing it. 我一直试图修复这个div的长度一段时间,我确信它是完全简单的东西,只是没有看到它。 The div for the content "page" is extending well beyond the footer and I can manipulate the length with the min-height property in css however I want to make sure that the footer/"page" div extend to bottom regardless of the content so I don't want to set a definite length for the div. 内容“页面”的div扩展到页脚之外,我可以用css中的min-height属性来操作长度,但是我想确保页脚/“页面”div延伸到底部而不管内容如何我不想为div设定一个明确的长度。

EDIT : jsfiddle: http://jsfiddle.net/F2SMX/ 编辑 :jsfiddle: http//jsfiddle.net/F2SMX/

Footer cs 页脚cs

#footer {
    background: #365F91;
    color: #000000;
    width:100%;
    height: 35px;

    position:relative;

    bottom:0px;
    clear:both;
}

#footer p {
    margin: 0;
    text-align: center;
    font-size: 77%;
}

#footer a {
    text-decoration: underline;
    color: #FFFFFF;
}

#footer a:hover {
    text-decoration: none;
}

changing footer position from relative to absolute had no change 将页脚位置从相对位置更改为绝对位置没有任何变化

Change relative to absolute , and remove min-height from #page . relative对于absolute更改,并从#page删除min-height

#footer { position: absolute; }

You'll also need to make sure that you only have 1 #page per page. 您还需要确保你只有1个#page每页。

Working fiddle . 工作小提琴

You want to use something called sticky footer. 你想使用一种叫做粘性页脚的东西。

http://css-tricks.com/snippets/css/sticky-footer/ http://css-tricks.com/snippets/css/sticky-footer/

Or you can use my solution without using pseudo class :after 或者你可以使用我的解决方案而不使用伪类:after

EDIT: sorry here you have my solution to problem with div instead of after http://codepen.io/anon/pen/LsFIn 编辑:对不起,你有解决问题的解决方案而不是http://codepen.io/anon/pen/LsFIn

Go old school.....add this to you css of #footer 去老派.....把它添加到#footer CSS中

bottom: -500px;
padding-bottom: -500px;

working demo 工作演示

CSS CSS

#footer {
        background: #365F91;
        color: #000000;
        width:100%;
        height: 80px;
        position:relative;
        bottom: -500px; /* push to the bottom */
        padding-bottom: -500px; /* maintain equilibrium by giving footer its height!!*/
    }

EDIT 编辑

to make footer stretch to height, if content exceeds 如果内容超过,则使页脚伸展到高度

demo 演示

#footer {
        background: #365F91;
        color: #000000;
        width:100%;
        min-height: 80px; /*change height to min-height, this will always cover the content height*/
        position:relative;
        bottom: -500px;
        padding-bottom: -500px;

    }

If you want a scrollable footer if content exceeds 如果内容超出,则需要可滚动页脚

demo 演示

#footer {
        background: #365F91;
        color: #000000;
        width:100%;
        height: 80px; /*keep height fixed*/
        overflow-y:scroll; /*scroll when content size increases */
        position:relative;
        bottom: -500px;
        padding-bottom: -500px;

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM