By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,648 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,648 IT Pros & Developers. It's quick & easy.

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

P: 8
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:

http://csszengarden.com/?cssfile=htt.../zengarden.css

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.

Thanks!
Mar 22 '07 #1
Share this Question
Share on Google+
3 Replies


P: 8
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

Thanks!
Mar 22 '07 #2

acoder
Expert Mod 15k+
P: 16,027
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

drhowarddrfine
Expert 5K+
P: 7,435
: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.