Full Scalable Background Images
Recently we worked on creating the new Fashion for All web site. F4a is a national non-profit in the US. The aim is to offer women living in low-income communities a day of dignified shopping and access to community-based organizations, which provide educational, career, health, wellness, and parenting resources. It’s about providing the tools and resources for women to achieve personal and professional growth. A good cause indeed.
The branding for f4a was done by a very creative group who handed over a PSD for the homepage, along with some minor requirements/requests. The main one, and the one that had me Googling a bit: to have the background photograph expand/shrink with the browser window. I’d seen this done before, but never tried it out myself – always great to have a challenge and learn something new. I Googled and found a few techniques for this – some much better than others.
Until CSS3 is widely accepted by browsers (come on, come on! do you know the great things you can do with CSS3?), we have to look at other options. If CSS3 was an option, this is all we’d need:
body {
background: url(bgimage.jpg) no-repeat;
background-size: 100%;
}
Ahh, so neat and compact. But, alas, this is not an option yet. So, we fake it.
There are options, using only CSS, that allow us to set the background image to the full width and height of the page. The problem though is proportions. When you expand the browser horizontally only, or vertically only, the image expands but distorts because it doesn’t expand proportionally. We want to keep the image looking “normal”. After some Googling, I came across this from Kimili.com and it was the best solution I found for what was needed: Flexible Scalable Background Image. Michael gives a detailed tutorial on how to set this up with a working example to reference as well. If you have been thinking about using this technique, this is the tutorial for you.
A passing word of advice: when adding the JavaScript call, keep it in the <body>. I initially placed it in the <head> out of habit and wondered why it wasn’t working.
And we took it a step further by making the background image a custom field in WordPress so that each page can have a specific background image. If nothing is set, then it uses the default homepage image. This also allows the folks at f4a to easily update the background image for each page as they do more events.
<?php if ( $image ): ?>
<style type="text/css">
body { background-image: url(<?php echo $image; ?>);}
</style>
<?php endif; ?>

December 14th, 2009 at 11:06 pm
I too had javascript call in and spent hours scratching my head before stumbling on your blog. Thanks!
April 9th, 2010 at 8:56 pm
I really like the f4a idea and website. I would love to emulate that full background concept on a Wordpress site.
Perhaps I am not following, but I cannot figure out the exact steps to do this for a Wordpress blog.
Can you elaborate more please?
Thank you
October 10th, 2010 at 1:03 pm
I’m with JON on this. I would really like to know how to apply this to a wordpress site :)
Thanks in advance
October 13th, 2010 at 8:58 pm
@Rennes – I just emailed you some additional details. Let me know if that helps. I had sent this same information to Jon and forgot to comment about it here. Cheers!
October 23rd, 2010 at 1:09 pm
This is awesome, I am also trying to implement this in wordpress. I would be really grateful of you could send me more details.
Thanks so much.
Tyron
October 23rd, 2010 at 3:58 pm
Wow I managed to get it working in wordpress. One question though…do you know if this would work if you added it to a “container” div instead of “body”? Or how to change the code to use it in a “container” div?
Thanks so much.
October 30th, 2010 at 5:56 pm
Lorissa,
Could you possibly send me the additional info too?!?!
Thanks!
November 2nd, 2010 at 10:13 pm
That’d be great if someone could post how to add this as a custom field in Wordpress. Thanks!
December 7th, 2010 at 4:51 pm
Would you be so nice the send me the info’s too? I’m very interested in your post!
Thanks a lot!
December 21st, 2010 at 9:35 pm
Lorissa,
This is really sweet. I was wondering if you could send me the additional information too.
Thank you
December 23rd, 2010 at 6:45 pm
No problem at all. I’ve emailed everyone, but let me know if I missed you. Cheers!
January 5th, 2011 at 8:05 pm
FINALLY! Would love to implement this in a wordpress site I am working on. Could you send me the steps/details as well?
Thank you son much and HAPPY NEW YEAR!
February 16th, 2011 at 7:23 pm
Would you be so nice the send me the info’s about how to integrate it into wordpress too? I’m very interested in your post!
thank you so much!
February 23rd, 2011 at 6:58 pm
Can you send the how-to or a link of how to add this scalable background images from ai in Wordpress? Have been looking for this for a while. Thanks so much!
March 20th, 2011 at 5:02 pm
I’m just getting started with wordpress, I’d love to know more on how this is accomplished on wordpress.
Thanks so much!