title: Image grid with autorescaling in HTML & CSS Only
body: <p>I have been trying to make a responsive auto rescaling image grid to display ads on our website. I used this as a reference - <a href="https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_images_side_by_side" rel="nofollow noreferrer">W3Schools-ImageGridMaker</a></p>
  
  <p>Based on that, I tried 4days to come up with this piece of code.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>div.gallery {
    border: 1px solid #ccc;
  }
  
  div.gallery:hover {
    border: 1px solid #777;
  }
  
  div.gallery img {
    display: block;
    object-fit: contain;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
  }
  
  div.desc {
    padding: 15px;
    text-align: center;
  }
  
  * {
    box-sizing: border-box;
  }
  
  .responsive {
    padding: 0 6px;
    float: left;
    width: 24.99999%;
  }
  
  @media only screen and (max-width: 700px) {
    .responsive {
      width: 49.99999%;
      margin: 6px 0;
    }
  }
  
  @media only screen and (max-width: 500px) {
    .responsive {
      width: 100%;
    }
  }
  
  .clearfix:after {
    content: "";
    display: table;
    clear: both;
  }
  
  div.boxed {
    border: 5px solid red;
    width: 100%;
    height: auto;
    overflow: auto;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="boxed"&gt;
  
    &lt;div class="responsive"&gt;
      &lt;div class="gallery"&gt;
        &lt;a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"&gt; &lt;img src="https://i.imgur.com/UgPbxk2.jpg" alt="Shiva1"&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  
    &lt;div class="responsive"&gt;
      &lt;div class="gallery"&gt;
        &lt;a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"&gt; &lt;img src="https://i.imgur.com/ColLeDr.png" alt="Shiva2"&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div class="responsive"&gt;
      &lt;div class="gallery"&gt;
        &lt;a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"&gt; &lt;img src="https://i.imgur.com/gVjcLg2.jpg" alt="Shiva3"&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    &lt;div class="responsive"&gt;
      &lt;div class="gallery"&gt;
        &lt;a target="_blank" href="https://tnilive.com" onclick="window.open('https://www.google.com'); window.open('https://www.yahoo.com');"&gt; &lt;img src="https://i.imgur.com/nxGxovl.png" alt="Shiva4"&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>This code is responsive, and on mobiles I got no problem because it looks neat by filling the full area. But if you look at it on a desktop, it injects empty space underneath some pics that doesn't fit the height. I am using bunch of URLs and can feed them as a list so that this 1280X200px area on desktop fills up neat with images that are of different sizes. I tried looking into freewall and a ton of other jsfiddles and pens but couldn't achieve on how to make the whitespace removed and make that particular box look good. Thanks.</p>