将“max-width”设置为较大设备的背景图片

问题描述:

我已将背景图片设置为div,但我不希望它的宽度超过1600px。例如,如果它显示在宽度大于1600像素的设备上,我不希望背景图像覆盖整个宽度。有没有办法实现这一目标?将“max-width”设置为较大设备的背景图片

这是我目前拥有的。无论设备有多宽,图像都覆盖整个宽度。我需要它停在1600px的宽度。

div { 
    background: url("img/bg.jpg") no-repeat center top #067AB4; 
    background-size: cover; 
} 
+0

你可以在这里阅读:https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries 请注意IE8:http://caniuse.com/#feat=css-mediaqueries – Kristiyan 2014-09-04 11:53:17

使用下面的代码在你的CSS文件:

@media (min-width: 1600px) { 
    div { 
    background: url("img/bg.jpg") no-repeat center top #067AB4; 
    background-size: 1600px 100%; 
    } 
}