简体   繁体   中英

Is there any way to resize the images based on screen resolution with out using javascript?

I am planning to use a big banner image in my website(976X450).Now in higher resolution monitors the image should stretch to occupy the space. Is there any way to do this with out using different images for different resolution?

Just start with the detection of screen dimensions and continue from there:

var width = screen.width;
var height = screen.height;

var img = document.getElementById(image_id);

img.height = img.height * width / img.width;
img.width = width;

Update :

Use CSS:

img#in_question { width: 100% }
#HeaderImage {
   height: 20%;
   width: 100%;
   background-repeat:repeat-x;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM