这是问题所在:我想要一段CSS代码,可以根据使用的电脑分辨率自动调整我的网站背景大小。
这意味着,例如,如果用户调整浏览器窗口大小,图像不会被调整大小(而不像.stretch值,需明确)。
这意味着,例如,如果用户调整浏览器窗口大小,图像不会被调整大小(而不像.stretch值,需明确)。
html {
background: url(images/bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
}
欲了解更多信息,请查看以下问答:
如果您不需要响应式图片,请从html
选择器中删除CSS3声明:
html {
background: url(images/bg.jpg) no-repeat center center fixed;
}
这可能会有所帮助...
background-size:contain;background-origin:content-box;
这将帮助您在正常屏幕大小下保持图像的原始大小,并根据div大小的更改进行调整。但是我们必须将高度保持为自动。否则,其高度将影响背景图像的大小。
window.screen.width
和window.screen.height
。 - Vitim.us@media
查询就不起作用了,不是吗? - brandonscript