【发布时间】:2016-08-24 20:17:32
【问题描述】:
如果我创建一个容器并想根据媒体查询设置背景图片,为什么浏览器(Firefox,Chrome)下载中等大小的图片,如果已经下载了大图片?这似乎完全违背了这一点(即节省带宽)。
HTML
<div id="background"></div>
CSS
#background {
width: 100%;
height: 400px;
background-image: url(/content/images/2016/04/airport-small.jpg);
background-size: cover;
background-repeat: no-repeat;
background-position: center;
}
@media (min-width: 500px) {
#background {
background: url(/content/images/2016/04/airport-medium.jpg);
}
}
@media (min-width: 800px) {
#background {
background: url(/content/images/2016/04/airport-large.jpg);
}
}
如果我加载一个页面,浏览器会在此设置中下载-large.jpg。如果我调整屏幕大小(低于 800 像素),浏览器会下载并呈现 -medium.jpg,依此类推。
如何防止这种情况发生?
【问题讨论】:
标签: image css responsive-design media-queries