I have a bunch of elements with an unknown number, and I need them to always be accompanied by another element next to them in this pattern:
╔═══════╦═══╗
║ ║ ║
╠═══════╣ ║
║ ║ ║
╠═══════╣ ║
║ ║ ║
╠═══════╣ ║
║ ║ ║
╚═══════╩═══╝
They must remain within the same container, as my CSS is already intricate and I am collaborating with others. Changing it all would be complex.
I attempted setting grid-row
on the right element to 1 / -1
, but negative values require grid-template-rows
to be explicitly set, which is not feasible since the number of columns is unknown.
I also tried using a CSS counter to dynamically set either grid-row-end: counter(count)
or
grid-template-rows: repeat(counter(count), auto)
, but it did not display a numerical output.
What is the best solution? Should I resort to having two separate containers? Using JavaScript is not ideal either.
Edit: A potential workaround, although not foolproof, involves setting grid-column: 1 / span 99
. Initially, I tried 1 / 99
, but the former is more effective and does not introduce additional rows.