Html div位置固定在网页顶部
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8935704/
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
Div position fixed on the top of web page
提问by Adham
How to make a div to always appear at the top of a web page even when the paged is scrolled vertically.
即使垂直滚动分页,如何使 div 始终显示在网页顶部。
回答by paislee
Use CSS position: fixed;
:
使用 CSS position: fixed;
:
#topdiv {
position: fixed;
top: 0;
}
See jsFiddle example: http://jsfiddle.net/CXACT/1/
参见 jsFiddle 示例:http: //jsfiddle.net/CXACT/1/
回答by Gelin Luo
div#myDiv {position: fixed; top: 0px; ...}
div#myDiv {position: fixed; top: 0px; ...}
回答by Dauezevy
Css :
css :
#topdiv {
position: fixed;
top: 0;
}
You can also make with JQuery,
你也可以用 JQuery 制作,
Just always take the scrolltop value and change the div top.
只需始终采用 scrolltop 值并更改 div 顶部。
$("#topdiv").css("top", scrolltop);