Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i have a div stuck on the left side of the page no matter how much i scroll horizontally?

This is kind of difficult to explain so ill link to a page that has the effect i need;

http://wpaoli.building58.com/wp-content/uploads/2009/08/feedback-panel.html

The feedback thing on the left side is what im trying to implement on my side, instead of feedback im going to use it as a navigation menu that shows up when clicked on.

the things above is what i have right now.

my problem is when i scroll to the right ( my page is around 6000px wide ) i want it to stay on the left side, is there a way to pull this off?

(this is to much for my brain to handle)..thanks!

like image 462
Noor Avatar asked Apr 20 '10 20:04

Noor


People also ask

How do I keep my div fixed when scrolling?

The interesting rule here is the ' position: fixed ', that makes the DIV stay fixed on the screen. The ' top: 50% ' and ' right: 0 ' determine where the DIV is displayed, in this case: 50% down from the top of the window, and a constant 0px from the right.

How do I make my div overflow horizontally?

Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line. Here the scroll div will be horizontally scrollable.

How do you stick a div to the right side of the screen?

To align a div with fixed position on the right side, we set the right CSS property of the div we want to align to the right side. to add a div with the class test . Then in the CSS code, we select the elements with class test , and set the right property on it.

How do you use sticky position?

To see the effect of sticky positioning, select the position: sticky option and scroll this container. The element will scroll along with its container, until it is at the top of the container (or reaches the offset specified in top ), and will then stop scrolling, so it stays visible.


1 Answers

Set the div to have a "position:fixed" style and then set "left:0px;top:0px". This makes the div stick to the top left of the browser instead of its relative position within the HTML flow.

Have a look at this example page, it has 2 fixed elements, one at the top left and the other at the bottom right:

Fixed example

like image 190
Brian Scott Avatar answered Sep 22 '22 17:09

Brian Scott