Does anyone know how to make a background image scale to 100% of the browser width? See this example for a visual reference of what I’m asking. In the example, how would you make the beach picture scale to 100% of the window so you’d never see it’s side edges as you make the browser window larger and smaller?
I know but I’m saying I don’t think that it is possible: I tried to stretch it across the entire screen so the black didn’t appear but I found repositioning it shortened the black space so it is less subtle.
A background image cannot be stretched. In the linked site, the image is an actual <img> tag in the html, and this can be set to 100% width in the css. Such resizing by the browser will lead to a reduction in image quality, so this is better suited to lower resolution images.
I think the opacity of the blurred image is changed via javascript after the content loads.
To apply a similar resizing technique to your example site, the background image would be moved to the html before any other content, and positioned absolutely behind the content in the css :
praxis, can you show us the update when you’re done?
Can I take this thread as absolute confirmation that there is no way to stretch background images?
I once wanted a background image to “stretch” with the browser, but a logo and text image to “sit on top” and not stretch out of proportion. How would I code that?
Many thanks. This site rocks and I love the podcast… it’s fairly clear even to a newbie like me.
With the image in the html as I outlined above, just setting the width only in percent will maintain the aspect ratio of the image - if you set both width and height, then you can stretch it out of proportion.
Nice! Now I see what you were after. So you can show clients a mock-up without the header navbar functional yet? Cool… I’ll have to remember that. It would save time to just show them the home page and at least get a visual cue for what they are after.
When CSS3 is implemented by all the browsers you will be able to use…
background-size: 100% 100%;
however as this has not been implemented, the only way you can achieve a explicitly sized image in the background is using the above method, by using z-index and absolute positioning, you can simply layer your design over the img tag and achieve the same effect… it means that a part of the style is unfortunately placed into the mark-up, but it’s the only way it can be achieved currently.
I first saw this technique on the below website… and I really am excited about when browsers can natively support it!