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