Position Absolute and Bottom 0

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

http://cdpn.io/FykHr I seem to have an issue with the combined CSS properties:

position: absolute; bottom: 0; 

First you can see that the .footer div doesn't isn't at the bottom. Now, change the font-size from 120px to 50px and the div seems to be working the way I inteded it to.

How do I make the .footer div stay at the bottom (not fixed at the bottom of the screen) regardless of the size of the .content div.

回答1:

You need to add position: relative; to the parent container, which in this case is .wrapper.

Here's a good reference page on absolute positioning.



回答2:

There is one way to do that:

body {     height: 100%;     margin: 0; } html {     padding-bottom: 50px;     min-height: 100%;     box-sizing: border-box;     -moz-box-sizing: border-box;     position: relative; }  footer {     position: absolute;     bottom: 0;     left: 0;     right: 0;     height: 50px;     background-color: red; } 

http://jsfiddle.net/n8UNM/

There is still one limitation. You have to know height of footer and set it in two places.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!