467,212 Members | 1,109 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,212 developers. It's quick & easy.

CSS "background-position: fixed;" problem, workaround with JS?

Hello forum friends. I performed a search on this topic, but I couldn't find anything useful. I wasn't really sure what to search.

First I'll state what I am trying to do. I recently agreed to make a site for a friend. It's good practice for me. The site will have (among other things) a biography. I told him to look at Zen Garden and find some layouts, and I'd see what I can do. His favorite layout for Biography is:


Only heres the kicker, we want the layout centered. I realize from researching this zen garden layout, that centering this particular layout is not possible with CSS alone. Reason being, fixed backgrounds are relative to the viewport and not the containing element. I found that this is not a bug, but is (understandably) a W3C standard spec. In most cases, a fixed background relative to the viewport is desirable, but not in my case. In a Google frenzy, I also found that using "background-position: fixed" relative to the containing element will most likely be available in CSS3 (I cannot remember my sources on this), but at this moment these options are far from realization.

Finally My Question:
Is there an unobtrusive workaround with JavaScript which can simulate fixed background positioning relative to the containing element? Or, I suppose I could say, is there a script which could cause the layout above to work when centered, without breaking the page when scripting is turned off?

I understand JavaScript syntax, and when I study code by constantly referring to the W3Schools reference I can eventually understand most of it; however, I am still very new to DOM objects, and the properties and methods of each.

I hope I made this question understandable. I wasn't sure how to word it.

Mar 22 '07 #1
  • viewed: 7385
3 Replies
I would like to correct above where I said "background-position: fixed" I did mean, "background-attachment: fixed".

Nonetheless, I actually found a work-around for this, which is not the best but it works. I just made the image the size of the containing element, which in this case isn't very large. Then I used "background-position: 50% 0;" which did exactly as planned.

A big bummer though. I've had IE7 for a while now, and I decided to download IE6 for testing reasons. I tested this layout in IE6 and it appears to be broken, even on the Zen Garden layout. I will instead be requiring an IE6 workaround, which I know I can find eventually.

If you would like to help me with this, I would be honored :-D

Mar 22 '07 #2
Expert Mod 8TB
You'll probably find better help on this in the HTML/CSS forum, but I'll copy it over instead of completely moving it in case we can have both a CSS solution and a JS workaround. I think, though, that you'd prefer the former over the latter.
Mar 23 '07 #3
Expert 4TB
:fixed has never worked in IE6. There are js workarounds for position:fixed and css workarounds but I don't know about background image fixes. Here's a CSS solution for position:fixed if it helps at all.
Mar 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

17 posts views Thread by Torbjørn Pettersen | last post: by
4 posts views Thread by Charles Law | last post: by
1 post views Thread by wstach@gmail.com | last post: by
7 posts views Thread by chardish@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.