开发者

javascript resize background image

Is it possible to resize a background image on load using javascrip开发者_StackOverflow中文版t? 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;
}


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.


Background images cannot be resized.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜