Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable the body scroll, but keep it on individual div elements which are greater in height than the browser

I have searched everywhere and have yet to get a solution. Okay heres the deal, I have a one page website which has several div elements underneath each other, sort of acting like individual pages I guess. What I want to achieve is to disable the scrolling of the actual web page all together, yet keeping the scroll of the active div in play if it goes below the web browser. To get to each other section of the page is simple done by using anchor links on the header.

like image 737
Muhammed Bhikha Avatar asked Oct 23 '22 05:10

Muhammed Bhikha


1 Answers

I'm not exactly sure what you're looking for, but I think you want a div to be scrollable, but not the actual document. You can do this by absolutely positioning the div on the screen with a fixed height and set the overflow to auto. I've done this using the following CSS code:

#scrollable {
    position: absolute;
    top: 10px;
    right: 10px;
    bottom: 10px;
    left: 10px;
    overflow: auto;
}​

See an example: http://jsfiddle.net/rustyjeans/rgzBE/

like image 88
Rusty Jeans Avatar answered Oct 30 '22 17:10

Rusty Jeans