does grid css has flex-direction: column/row reverse option

does grid css has flex-direction: column/row reverse option
29 Replies
ἔρως
ἔρως3w ago
no you can emulate it by giving the elements a grid area and then you position the grid areas in reverse order
Rägnar O'ock
Rägnar O'ock3w ago
actually it kinda has with the grid-auto-flow property
MDN Web Docs
grid-auto-flow - CSS: Cascading Style Sheets | MDN
The grid-auto-flow CSS property controls how the auto-placement algorithm works, specifying exactly how auto-placed items get flowed into the grid.
Rägnar O'ock
Rägnar O'ock3w ago
that lets you tell the grid which axis should be used to "stack" elements and if it should try to fill the gaps with smaller items or not
ἔρως
ἔρως3w ago
but doesnt do the reverse
Rägnar O'ock
Rägnar O'ock3w ago
hense "kinda"
ἔρως
ἔρως3w ago
yeah it's so close
bfmv
bfmvOP3w ago
a major drawback of grid
Rägnar O'ock
Rägnar O'ock3w ago
how so?
bfmv
bfmvOP3w ago
its such a commonly required property
ἔρως
ἔρως3w ago
not for grid just because everything fits in the square hole doesn't mean it's a square
bfmv
bfmvOP3w ago
but would it be any effort to introduce this feature in grid they could just do it
ἔρως
ἔρως3w ago
or just use flex
bfmv
bfmvOP3w ago
it would definitely be much more used than some property and attributes
ἔρως
ἔρως3w ago
what exactly are you trying to do?
bfmv
bfmvOP3w ago
yeah the thing im doing is suited for flex much more
Rägnar O'ock
Rägnar O'ock3w ago
the grid spec is way more complex than it looks so I would not bet on that. And flow order in grid is basically never useful
ἔρως
ἔρως3w ago
in the time ive been here, you are the first person asking to reverse a grid
bfmv
bfmvOP3w ago
i have a container that contains two boxes, and i want the order to be reversed once it reaches a certain device size i know flex is more suited for this but i was thinking about other situations maybe i should just use flex
Rägnar O'ock
Rägnar O'ock3w ago
if you know the number of items is fixed you should just use grid-areas tho, having elements in a different order in the DOM and on screen might lead to accessibility issues (tabindex for example will not make sense visually). Depending on the case it might be fine, but you should keep that in mind.
ἔρως
ἔρως3w ago
ah, you can just do what i said or manually set the start/end column on both either of these will work also, make sure that you have the sizes reversed too if they are different
Rägnar O'ock
Rägnar O'ock3w ago
or just use flex
bfmv
bfmvOP3w ago
👍
capt_uhu
capt_uhu3w ago
The CSSWG resolved to add row-reverse, column-reverse, and wrap-reverse in Nov 2023. So it's in the browsers court now but no browser has done anything with it yet. There's a chrome bug if you want it go give that a +1 https://issues.chromium.org/issues/40287554
ἔρως
ἔρως3w ago
🤔 that is interesting personally, i cant see a good use for it, as swapping the areas/rows/columns gives more control it's a bit tedious, but less limiting, as you can do row and column reverse at the same time ... manually
Rägnar O'ock
Rägnar O'ock3w ago
it's usefull when you don't know the number of items you'll have or if you use an implicit grid
ἔρως
ἔρως3w ago
that is the only thing i came up with but in those cases, i see flex being more useful even if you have to grid with flex
Rägnar O'ock
Rägnar O'ock3w ago
it can... but that depends on the design like if you have an infinite scroll grid that must be responsive (adding or removeing column as the screen width changes), using flex might not be ideal in this situation but you might want to fill the grid from right to left or from the bottom up (no idea why you would tho)
ἔρως
ἔρως3w ago
that's a good point very very very niche
b1mind
b1mind3w ago
Grid areas is teh way 🥲
'this that'

'that'
'this'
'this that'

'that'
'this'
But yea be nice if the row/column-reverse actually worked proper in auto-flow

Did you find this page helpful?