CSS 将元素与窗口底部对齐
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6029102/
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
align an element to the bottom of window
提问by Xavier
I am trying to use jQuery to calculate the window height then apply that value to a DIV (the container div) finally i want the jQuery to align an element to the bottom of the page.
我正在尝试使用 jQuery 来计算窗口高度,然后将该值应用于 DIV(容器 div),最后我希望 jQuery 将元素与页面底部对齐。
<div id="wrapper">
<div id="element-align">Here is the element i wish to align to the bottom</div>
</div>
回答by Rory McCrossan
Further to my question on your OP, this can be done in CSS:
关于我对您的 OP 的问题,这可以在 CSS 中完成:
#element-align {
position: fixed;
bottom: 0;
}
If needs be you can also add left/right to the element, but the fixed positioning will mean that the element will always appear in the same place relative to the browser chrome, regardless of the scroll position of the page.
如果需要,您还可以向元素添加左/右,但固定定位意味着元素将始终出现在相对于浏览器镶边的相同位置,而不管页面的滚动位置如何。