I have an JPG image with size 1024 x 724. My page size is not fixed. My requirement is: If I resize the page then the background image should also resize and fit to the page.
Also I don't want to keep the image related information in my Html page/JSP. I want to do this using plain CSS. I am not using CSS3. Because there is an attribute called background-size
which can make the image stretch to the page width and height. Currently only Google Chrome supports this.
Any help ?
You can't resize background images with CSS2.
What you can do is have a container that resizes:
<div style='position:absolute;z-index:0;left:0;top:0;width:100%;height:100%'>
<img src='whatever.jpg' style='width:100%;height:100%' alt='[]' />
</div>
This way, the div
will sit behind the page and take up the whole space, while resizing as needed. The img
inside will automatically resize to fit the div
.