Html 在屏幕底部放置一个 div,而不是页面

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

Put a div on bottom of the screen, not page

htmlcssalignmentprogress-bar

提问by Nikolas

I am trying to put a gray bar on the bottom of the screen of my webpage, regardless of the resolution. However, when I try, it seems to just go up or down when I go in a different resolution. Is there any way to fix this?

无论分辨率如何,我都试图在我的网页屏幕底部放置一个灰色条。然而,当我尝试时,当我进入不同的分辨率时,它似乎只是上升或下降。有没有什么办法解决这一问题?

Also, the bar is made out of CSS using the divid tag.

此外,该栏是使用divid 标签由 CSS 制成的。

/* HTML*/
<div id="info">Scroll for info</div>

/* CSS */
<style>
#info { 
    height: 40px; 
    position: relative; 
    margin-top: 25%; 
    background-color: #393838; 
    opacity: 
}
</style>

EDIT:I want it to be on the bottom of the screen, but then when I scroll down it goes up towards the top of my screen.

编辑:我希望它位于屏幕底部,但是当我向下滚动时,它会向上移动到屏幕顶部。

回答by putvande

If you want it on the bottom and always at the bottom, you have to use position: fixed. You could try this:

如果您希望它位于底部并始终位于底部,则必须使用position: fixed. 你可以试试这个:

#info { 
    height: 40px; 
    position: fixed; 
    bottom:0%;
    width:100%; 
    background-color: #393838; 
    opacity: 1;
}

http://jsfiddle.net/rX4nd/1/

http://jsfiddle.net/rX4nd/1/

回答by MastaBaba

How about adding entering as well?

添加输入怎么样?

.someDiv {
  position:fixed;
  width:50%;
  height:300px;
  margin-left:-25%;
  background:#063;
  bottom:0px;
  left:50%;
}