【发布时间】:2016-10-09 01:24:39
【问题描述】:
我喜欢 img 标签在响应式设计中的工作方式。它按比例调整大小并扩展包含它的 div。问题是图像在每种尺寸下都是相同的像素数,这对于移动设备来说是很糟糕的。
我想到了一种方法,在标记中使用具有宽度和高度属性的 1x1 像素 PNG 图像来定义比例。这样,您的 div 将根据 PNG 按比例调整大小,并且您可以使用媒体查询交换背景。您可以在整个页面中多次使用它,只需一个 http 请求。
这种攻击响应式图像的方式有什么问题吗?
.container {
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-repeat: no-repeat;
border: 1px solid blue;
background-image: url(large.png)
}
@media screen and (max-width: 968px) {
.container {
background-image: url(small.png)
}
}
img {
width: 100%;
height: auto;
}
<div class="container">
<img src="1x1.png" width="5" height="1">
</div>
【问题讨论】:
标签: html css image responsive-design media-queries