【发布时间】:2022-12-28 03:49:50
【问题描述】:
Is there a way to achieve the following via CSS grid?
- If the number of items is odd, the first column should have 1 more row than the second column.
1 4 2 5 3- If the number of items is even, the columns should have the same number of rows.
1 3 2 4Tried using
grid-template-rowsbut the number of rows per column is fixed.
【问题讨论】:
-
No. the number of rows is required to be stated for this to work and even then CSS can't actuallycounthow many items there are.
-
it will always be 5 or 4 elements? if yes, it's possible
-
@TemaniAfif no, it's either odd or even number of elements.
-
I updated my answer to cover the generic case