Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fixed Positioning With Scrolling

Tags:

If, for example, I have a menu using fixed positioning but it's larger than the height of the current window, is there a way to allow this to scroll? The browser's default behaviour is to just hide it, and not let you access it.

div#sidebar {     position:fixed;     top:30px;     left:0;     bottom:4px;     width:148px;     background-color:#d7d7d7; } 

Here's a snippet of what I've currently got. Would it require some JavaScript or something along those lines?

EDIT: I'm not sure if this is actually possible to get correct. I want an element which is 30 pixels from the top of the document. I want to allow this to scroll using overflow:auto and height:100%. Either way I seem to do it, the scrollbar will be hidden, or a portion of the div will be hidden.

like image 261
Kezzer Avatar asked Mar 30 '09 11:03

Kezzer


People also ask

Which position stays where it is even when you scroll down the screen?

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled. The top, right, bottom, and left properties are used to position the element.

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

An element with position:fixed is fixed with respect to the viewport. It stays where it is, even if the document is scrolled.

How do I fix a div when scrolling?

To make div fixed scrolling to that div with CSS, we can use the position: sticky CSS property. position: -webkit-sticky; position: sticky; top: 0; z-index: 1; to set position to sticky and z-index to 1 to make the element with the sticky position show on top after we scroll to it.


1 Answers

You'll need to set overflow:scroll (or overflow:auto) to that div, and set height to 100%.

like image 154
Seb Avatar answered Oct 04 '22 18:10

Seb