title: Restricting responsive grid to 2 columns max?
body: <p>I have a two column layout in which one column displays a number of images on a grid. <strong>The size and number of the images vary.</strong> I want the images to either show one a line, or two per line, depending on the size of the image and the screen. I have the below grid set up:</p>
  <pre><code>@media (max-width: 2000px) {
    .productimg {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(195px, 2fr));
    grid-gap: 5px;
    grid-auto-flow: row dense;
    }
  </code></pre>
  <p>The images are given a class .u-max-full-width to keep them contained within the grid:</p>
  <pre><code>.u-max-full-width {
    max-width: 100%;
    box-sizing: border-box; }
  </code></pre>
  <p>For the most part this works. See below for the ideal layout:</p>
  <p><a href="https://i.stack.imgur.com/c1ba6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c1ba6.png" alt="enter image description here" /></a></p>
  <p>However, at certain screen widths the images break into three columns. This happens with particularly thin images as soon as it is possible to put three 195px width images on the same line. I thought it might be that the images reach their source width and then rather than remain there shrink back to 195px but they are moving down to 195px before reaching their max size.</p>
  <p>For example, images with a width of 336, 353, and 390 respectively will switch to a three col. when the container div is only 595px wide, more than small enough for the 336px and 353px images to fill it without forcing a third in.</p>
  <p><a href="https://i.stack.imgur.com/Q8SJX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q8SJX.png" alt="enter image description here" /></a></p>
  <p>If I increase the min width this solves the issue, however, the images will not properly fall into two rows at smaller resolutions. I tried using a @media declaration for the range where the container div can hold three 195px images, and declaring an absolute max size.</p>
  <pre><code>@media (min-width: 1542px) and (max-width: 2000px){ 
    .productimg {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(195px, 350px));
    grid-gap: 5px;
    grid-auto-flow: row dense;
    }
  </code></pre>
  <p>This does seem to prevent three columns from developing, but now it jumps from two to one columns between 1541 and 1542px in screen width because the max width is being prioritized, which is not what I want at all.</p>
  <p><a href="https://i.stack.imgur.com/ZHIwo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZHIwo.png" alt="enter image description here" /></a></p>
  <p>What I want to do is keep the columns to a maximum of two but to fill the row completely as long as the images are not smaller than 195px in width, but I can't seem to find any way to do that simply. I have looked at all of the various formatting declarations for grid, but am struggling to conceptualize their use. I wonder if grid is even the appropriate tool to use in this situation, but I haven't found any better solution.</p>
  <p>Any assistance in this issue would be appreciated.</p>