jQuery 如何在页面底部定位div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5548142/
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-26 19:20:55  来源:igfitidea点击:

How to position div at the bottom of a page

jqueryhtmlcssposition

提问by Shahin

How can I set position of a <div>to the bottom of page with either CSS or jQuery?

如何<div>使用 CSS 或 jQuery将 a 的位置设置到页面底部?

回答by Hussein

Use position:absoluteand bottom:0

使用position:absolutebottom:0

Check working example. http://jsfiddle.net/gyExR/

检查工作示例。http://jsfiddle.net/gyExR/

回答by fabrik

You can use position:absolute;bottom:0;if that's all you want.

position:absolute;bottom:0;如果这就是你想要的,你可以使用。

回答by lmondria

in css: position:absoluteor position:fixed

在 css 中:位置:绝对位置:固定

回答by Stefan Haberl

This has been answered already, but to give a little bit more context for non CSS-experts:

这已经得到了回答,但要为非 CSS 专家提供更多背景信息:

Given the HTML

鉴于 HTML

<html>
  <body>
    <p>Some content</p>
    <div class="footer">down there</div>
  </body>
</html>

then the following css

然后下面的css

div.footer {
  position: absolute;
  bottom: 0;
  right: 0;
}

will position the text at the lower right corner of your viewport (browser window). Scrolling will move the footer text.

将文本定位在您的视口(浏览器窗口)的右下角。滚动将移动页脚文本。

If you use

如果你使用

div.footer {
  position: fixed;
  bottom: 0;
  right: 0;
}

on the other hand, the footer will stay at the bottom of your viewport, even if you scroll. The same technique can be used with top: 0and left: 0btw, to position an element at the top left corner.

另一方面,即使您滚动,页脚也将停留在视口的底部。同样的技术可以与top: 0left: 0btw一起使用,将元素定位在左上角。

回答by Shrinivas Naik

The combination position:fixed;with bottom:0;works for me.

position:fixed;与的组合bottom:0;对我有用。

回答by Gilberto Giro

I think you can do this:

我认为你可以这样做:

    html{
      min-height:100%;
      position:relative;
      background-color:red;
    }
    .footer{
      bottom:0;
      position:absolute;
      background-color:blue;
    }
<html>
  <body>
    <div class='footer'>
    <h1>I am Footer</h1>
    </div>
    </body>
  </html>