How do I get CSS columns to not spread out but instead bunch on the left
What I get
What I want
Example
body {
background-color: #c3dbff;
}
.cols {
columns: 250px; /* want however many 250px columns will fit */
}
.thing {
display: inline-block;
width: 240px;
background: red;
margin-bottom: 10px;
break-inside: avoid-column;
/* below just to make it clear the order of children in the columns */
color: white;
display: inline-grid;
place-content: center;
font-weight: bold;
font-family: sans-serif;
font-size: 50pt;
}
<div class="cols">
<div class="thing" style="height: 200px;">1</div>
<div class="thing" style="height: 200px;">2</div>
<div class="thing" style="height: 290px;">3</div>
<div class="thing" style="height: 280px;">4</div>
<div class="thing" style="height: 200px;">5</div>
<div class="thing" style="height: 230px;">6</div>
<div class="thing" style="height: 260px;">7</div>
<div class="thing" style="height: 210px;">8</div>
<div class="thing" style="height: 280px;">9</div>
<div class="thing" style="height: 230px;">10</div>
<div class="thing" style="height: 260px;">11</div>
<div class="thing" style="height: 210px;">12</div>
<div class="thing" style="height: 200px;">13</div>
<div class="thing" style="height: 270px;">14</div>
<div class="thing" style="height: 220px;">15</div>
<div class="thing" style="height: 260px;">16</div>
<div class="thing" style="height: 250px;">17</div>
<div class="thing" style="height: 290px;">18</div>
</div>
CSS only.
Things I tried,
setting
column-width: 250px. ❌setting the outer container to
display: inline-block;❌setting the outer container to
margin: 0 auto 0 0❌setting
column-gap: 10px❌setting
display: flex; flex-direction: column; flex-wrap: wrap❌This doesn't work because in order to wrap I'd have to give the flex box a height, otherwise it has no idea it needs to wrap. That's different that
columnswhich will figure out height after figuring out how many columns.
One thing that makes it hard to find an answer is most results about columns are not about the css columns property but about columns in tables, or grids, or flexbox
PS: No, I'm not trying to do a masonry layout out. I want the items to go down the first column, then flow into the second (vs masonry where they flow to the right first and then fill in the shortest column. not looking for that).

