Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Div fixed on Scrolling

How to make a div fixed on detection of Scrolling by the Users.
Example: Right Sidebar of Facebook, it gets stuck when a certain scroll position is attained.

like image 577
sandbox Avatar asked Mar 02 '12 10:03

sandbox


People also ask

How do I keep my div fixed when scrolling?

You can do this replacing position:absolute; by position:fixed; . Show activity on this post. There is something wrong with your code. This can be solved with position : fixed This property will make the element position fixed and still relative to the scroll.

How do you make a div fixed position?

Set everything up as you would if you want to position: absolute inside a position: relative container, and then create a new fixed position div inside the div with position: absolute , but do not set its top and left properties. It will then be fixed wherever you want it, relative to the container.

How do you freeze a div in HTML?

2 Answers. Show activity on this post. Add position: relative; to container, and remove floats and add position: fixed; to the block you want to fixate. I have actually tried exactly that, except I had left:5px instead of left:5 , and then the div was positioned relatively to the page instead of its parent.


1 Answers

position:fixed is the answer.
But you can always look at a website's source if you want to know how they do something. Very educational!

like image 93
Mr Lister Avatar answered Sep 28 '22 00:09

Mr Lister