Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

absolutely positioned divs that don't move when page is scrolled

I've done this in the past using a method similar to this: http://javascriptkit.com/javatutors/static3.shtml

but I don't like the "flicker" effect as the page is scrolled and the div needs to move with the scrolling. Lately I've seen a lot of site that have an element (a div or the like I presume) that don't move when the page is scrolled but it's seemless...they're just there and it's a beautiful thing.

Unfortunately I can't seem to recall where I've seen it lately to view the source and try to figure it out so I figured I'd turn here and see what all of you experts can provide as far as assistance / suggestions.

TIA

like image 666
Kyle Avatar asked May 18 '10 20:05

Kyle


People also ask

How do I keep my Div fixed when scrolling?

Use position: fixed instead of position: absolute .

How do you make the element not move when scrolling?

position:fixed; An element with fixed position is positioned relative to the browser window. It will not move even if the window is scrolled.

Which position will keep the element in the same place regardless of scrolling?

A fixed position element is positioned relative to the viewport, or the browser window itself. The viewport doesn't change when the window is scrolled, so a fixed positioned element will stay right where it is when the page is scrolled.

What is position sticky CSS?

position: sticky;A sticky element toggles between relative and fixed , depending on the scroll position. It is positioned relative until a given offset position is met in the viewport - then it "sticks" in place (like position:fixed).


1 Answers

Try setting "position: fixed" to the element.

I think this does not work with some IE versions, you'll have to us JS for that.

like image 121
jeanreis Avatar answered Oct 03 '22 04:10

jeanreis