http://codepen.io/anon/pen/OVWpvO
HTML
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
<img src="http://placehold.it/350x150">
css
body {text-align: center;}
img {
width: 20%;
margin: 10px;
}
@media (max-width: 1280px) {
img {width: 30%;}
}
@media (max-width: 980px) {
img {width: 45%;}
}
@media (max-width: 768px) {
img {width: 70%;}
}
或使用calc()的css;
body {text-align: center; margin: 0;}
img {
margin: 10px;
width: calc(100%/4 - 4*6px);
}
@media (max-width: 1280px) {
img {width: calc(100%/3 - 3*8px);}
}
@media (max-width: 980px) {
img {width: calc(100%/2 - 2*11px);}
}
@media (max-width: 768px) {
img {width: calc(100%);}
}
http://codepen.io/anon/pen/oXBZPL
这是非常接近的。唯一的区别是这个版本在包含图像的div的边上不保持相同的边距宽度。如果你看一下这个例子,图像周围的边距不会改变。某种方式重新计算图像大小以完全适合任何尺寸(和设备宽度)。 – Matthew6
添加更新与css calc版本 –
OMG,这是完美的!你钉了它,先生! – Matthew6