繁体   English   中英

有没有办法在不使用JavaScript的情况下根据屏幕分辨率调整图像大小?

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

我打算在我的网站(976X450)中使用大横幅图像。现在在高分辨率显示器中,图像应拉伸以占据空间。 有没有办法使用不同分辨率的不同图像来做到这一点?

从检测屏幕尺寸开始,然后继续:

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

var img = document.getElementById(image_id);

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

更新

使用CSS:

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

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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