views:

108

answers:

2

Is it possible to resize a background image on load using javascript? I don't care about dynamically resizing the image according to window size or anything, I just want to take large images and resize them to a specific width and height so that the full image fits inside a specific layout.

WORK AROUND:

I did what the people below said and used a regular tag that I sized accordingly and positioned absolutely in the containing div. I then used the z-index property to push it to the background.

img.background {
    position: absolute;
    top: 0;
    left: 0;
    width: 960px;
    z-index: 0;
}
+1  A: 

Background images cannot be resized.

Your best call is to use an <img> with position:absolute

nico
+1  A: 

It's not possible to [reliably, x-browser] scale a background image in any way at this point, but it is available in CSS3 (spec) so hope exists for the future.

Use an actual if you want to scale, in which case yes of course you can resize whenever you wish.

annakata