- Create Account

Position fixed in IE: another innocent(?) hack

Forums > General Topics > Position fixed in IE: another innocent(?) hack
Author
Message

1) molendijk Group: Members
Posts: 78 Joined: 29 Nov 2005 Location: The Netherlands (Groningen) IP: 84.86.--.--
Hallo Angus,
Sorry to bother you again about ways of achieving 'position:fixed' in IE. Just by accident, I found out that something like the following yields a fixed position in IE AND in normal browsers:

style="position:fixed;top:50%;left:2%;^position:absolute;top:expression(e v
al(document.compatMode && document.compatMode=='CSS1Compat') ?
documentElement.scrollTop+screen.height*0.35 : document.body.scrollTop+screen.height*0.35);"

You can replace the '^' by all sorts of (combinations of) symbols; the thing will continue to function OK (even in IE6 if you use '*+'), as long as you don't use aphabetic or plain numeric characters.

Is this a known fact? I didn't find it with Google. I tested it with many browsers except with IE7 (don't have that one).

I am very curious to know what you know about this.

Arie.
Arie.

2) Angus Turnbull Group: Moderators
Posts: 4042 Joined: 7 Dec 2003 Location: New Zealand IP: 192.188.--.--
I'd prefer to use IE's dedicated "conditional comments" (google for more) as it allows you to target specific versions of MSIE.

Otherwise, it's always good to use one way that works across all browsers. You can "fake" position:fixed by putting your content in a browser-window-sized <div> and using overflow:scroll on that, with other elements placed above/flow it -- that can work the same way everywhere.

Good luck - Angus.

3) molendijk Group: Members
Posts: 78 Joined: 29 Nov 2005 Location: The Netherlands (Groningen) IP: 84.86.--.--
Thanks a lot.
I agree on using the conditional comments.

Arie.
Arie.

Post a Reply:

You are not logged in, and will be posting anonymously as a guest. If you want to post using an account, please login at the top of this page.