views:

326

answers:

2

I'm trying to position a div at the top left corner of the page, and I want it to stay there regardless of browser window resizing or page scrolling.

How can I do this either with plain CSS (if possible), or with jQuery?

+5  A: 

use css position: fixed;

#fixedDiv {
    position: fixed;
    left: 20px;
    top:20px;
    width: 50px;
    height: 50px;
}

For IE6, see http://www.cssplay.co.uk/layouts/fixed.html

Andy E
Note that IE 6 and before don't support position:fixed, and IE7 and WebKit have weird bugs in regards to changing position to or from fixed (see http://quirksmode.org/css/position.html)
bdukes
good point, workaround available at: http://www.cssplay.co.uk/layouts/fixed.html
Andy E
luckily i dont have to support ie 6 ( internal company app ), but very useful for future visitors. thanks. :)
Ian
+2  A: 
css-selector {
    position: fixed;
    top: 0;
    left: 0;
}

Take care of the z-index. Higher = foreground.

Tammo