I'm using the CSS multi-column layout for this layout:
I want the content to use as many columns as possible. It does that in the above image, but when there's only 3 items, it does the following:
I would like the box "3" to be to the right of box "2". Is that possible?
EDIT: looking for a general solution (this is a simplified example, we don't know the heights of the container or elements in advance).
EDIT 2: if there's a better way than using multi-column (perhaps grid?), we'd use that.
Here's the HTML/CSS (or jsfiddle here):
.container {
  column-width: 120px;
  column-gap: 20px;
  padding: 10px;
  width: 600px;
  height: 250px;
  border: 1px solid blue;
}
.item {
  
  background: #2371f3;
  padding: 5px;
  height: 100px;
  width: 100px;
  color: white;
  break-inside: avoid;
  /* Workaround for Firefox bug (https://stackoverflow.com/a/7785711/2223706) */
  overflow: hidden;
  border: 1px solid darkblue;
}
.longer {
  height: 220px; /* Decreasing this to 200px makes #2 and #3 no longer stack. */
}<div class="container">
  <div class="item longer">1</div>
  <div class="item">2</div>
  <div class="item">3</div>
</div>

 
     
    