Adham
Adham

Reputation: 64904

Div position fixed on the top of web page

How to make a div to always appear at the top of a web page even when the paged is scrolled vertically.

Upvotes: 4

Views: 34515

Answers (3)

Dauezevy
Dauezevy

Reputation: 1080

Css :

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

You can also make with JQuery,

Just always take the scrolltop value and change the div top.

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

Upvotes: 0

calebds
calebds

Reputation: 26238

Use CSS position: fixed;:

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

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

Upvotes: 10

Gelin Luo
Gelin Luo

Reputation: 14393

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

Upvotes: 2

Related Questions