Stopping DIV elements scrolling with page?

Is there a way to fix DIV elements and stop them scrolling with the rest of the page? -10 points if you suggest frames :wink:

-Sam

css is the answer


div#whatever {
    position: fixed;
    top: 100px;
    left: 20px; /*or whatever */
}

bear in mind that IE doesn’t like fixed positioning, though;

Always IE that has to be difficult isn’t it :rolleyes:

Thanks for the code though, I’ll use that unless someone can give me something else I can use :slight_smile:

It all depends where you want the fixed div?

If its a side bar or top bar then you can get around it by basically moving the body margins and placing the sidebar absolutely outside the body margins (there are a few loose ends to tie up).

Theres some more info here:

http://devnull.tagsoup.com/fixed/

Or you could use one of the js scripts to emulate position:fixed.

(Position fixed only works in ie on background images in the body element.)

Paul