Note that there are some explanatory texts on larger screens.

plurals
  1. POsimple CSS grid with unequal image sizes
    primarykey
    data
    text
    <p>I want to layout a list of images in a grid format. </p> <p>They shall behave like this:</p> <ul> <li>stretched to 100% of the screen width if viewed on small screens</li> <li>stretched to 50% of the screen width if viewed on tablet screens</li> <li>stretched to 25% of the screen width if viewed on large desktop screens</li> </ul> <p>I have something very close, but the problem is, the images have different sizes, and therefore the layout is broken. How should I fix the code so that the smaller image will be stretched bigger to match the bigger boxes automatically?</p> <p>See the problem here:<a href="http://jsfiddle.net/Gep2G/embedded/result/" rel="nofollow">http://jsfiddle.net/Gep2G/embedded/result/</a></p> <p>My HTML source code:</p> <pre><code>&lt;body&gt; &lt;div id='wrapper'&gt;&lt;img src='http://placekitten.com/352/288'/&gt;&lt;/div&gt; &lt;div id='wrapper'&gt;&lt;img src='http://placekitten.com/352/288'/&gt;&lt;/div&gt; &lt;div id='wrapper'&gt;&lt;img src='http://placekitten.com/352/288'/&gt;&lt;/div&gt; &lt;div id='wrapper'&gt;&lt;img src='http://placekitten.com/320/240'/&gt;&lt;/div&gt; &lt;div id='wrapper'&gt;&lt;img src='http://placekitten.com/320/240'/&gt;&lt;/div&gt; &lt;/body&gt; </code></pre> <p>My CSS:</p> <pre><code>body {margin:0;padding:0} img{width:100%;height:100%;} #wrapper{width:100%;float: left;} @media (min-width:320px) { /* smartphones, iPhone, portrait 480x320 phones */ body {margin:0;padding:0} img{width:100%;height:100%;} #wrapper{width:100%;float: left;} } @media (min-width:961px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ body {margin:0;padding:0} img{width:100%;height:100%;} #wrapper{width:50%;float: left;} } @media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ body {margin:0;padding:0} img{width:100%;height:100%;} #wrapper{width:50%;float: left;} } @media (min-width:1281px) { /* hi-res laptops and desktops */ body {margin:0;padding:0} img{width:100%;height:100%;} #wrapper{width:25%;float: left;} } </code></pre> <p>Editable code: <a href="http://jsfiddle.net/Gep2G/" rel="nofollow">http://jsfiddle.net/Gep2G/</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload