Div position is fixed at the top of the web page

How to make a div always appear at the top of a web page, even if the projected one scrolls vertically.

+4
source share
3 answers

Use CSS position: fixed; :

 #topdiv { position: fixed; top: 0; } 

See jsFiddle example: http://jsfiddle.net/CXACT/1/

+9
source

div#myDiv {position: fixed; top: 0px; ...}

+2
source

Css:

 #topdiv { position: fixed; top: 0; } 

You can also do using jQuery,

Always use the scrolltop value and change the top of the div.

 $("#topdiv").css("top", scrolltop); 
0
source

Source: https://habr.com/ru/post/1391961/


All Articles