In cases like this, I think flex
might be better suited because it does take into account the intrinsic size of the elements when placing items. The problem with something like:
grid-template-columns: repeat(auto-fill, minmax(256px, max-content))
is that you are saying your items may shrink down until 256px in width. In most cases, especially with dynamic content, you do not know how long the longest title, word, or element will be. This is what flexbox was made to do.
However, I was also hoping this was not the case. My use case was that I was tring to do space between a title and some buttons on the same row. At first thought, this should be accomplishable with subgrid, which allows alignment of subitems to affect other items. I spent the better part of a day trying to get it to where when one column wraps, the rest wrap. I did get a partial solution using the above grid-template-columns
, but the unfortunate part is that you cannot use intrinsic attributes for the auto-columns. This makes it so long titles might get cut off. Flexbox is the correct solution here, and it might be for you as well.