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
Put a div on bottom of the screen, not page
提问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 div
id tag.
此外,该栏是使用div
id 标签由 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;
}
回答by MastaBaba
How about adding entering as well?
添加输入怎么样?
.someDiv {
position:fixed;
width:50%;
height:300px;
margin-left:-25%;
background:#063;
bottom:0px;
left:50%;
}