Html 如何将 DIV 锚定到页面底部?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2971401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:19:34  来源:igfitidea点击:

How to anchor a DIV to the bottom of a page?

htmlcssalignment

提问by Nathan Osman

I have a fixed-width DIV that I want to remain at the bottom of the browser's viewport.

我有一个固定宽度的 DIV,我想保留在浏览器视口的底部。

Unfortunately, I haven't a clue where I would even begin to try to implement this.

不幸的是,我不知道我什至会开始尝试实现这一点。

Obviously the first thing to do is set positionto fixed. But beyond that... no clue.

显然首先要做的是设置positionfixed。但除此之外……没有任何线索。

回答by Sarfraz

See at css-tricks:

参见 css-tricks:

Fixed Footer

固定页脚

CSS:

CSS:

#footer {
   position:fixed;
   left:0px;
   bottom:0px;
   height:30px;
   width:100%;
   background:#999;
}

/* IE 6 */
* html #footer {
   position:absolute;
   top:expression((0-(footer.offsetHeight)+(document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight)+(ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop))+'px');
}

回答by airportyh

#mydiv{
   position: fixed;
   bottom: 0px;
}