3
3
11
u/MarmotOnTheRocks Jul 15 '21
My 2cents:
grid-column: 1 / -1It will span the element to all the available columns. Very very useful when you don't know the exact number of columns or you just want to be safe and fill the entire width (example: a header element).
1
u/Gin-Chan Jul 16 '21
The caveat to this is it will only work with the explicit grid (columns defined with
grid-template-columns) but not span implicit columns (grid-auto-columns).1
u/MarmotOnTheRocks Jul 16 '21
True, yes.
I was trying something and I got stuck on this pen. Boxes 2, 3 and 4 should equally space themselves to fit the entire width. They don't, why?
1
u/Gin-Chan Jul 16 '21
Because you're creating 4 grid columns here:
grid-template-columns: repeat(4, 1fr);. By default, each item in a grid takes up one cell. You have 4 items, the first one spans the entire row so the remaining three go into the next row. So the last cell stay empty. If you change it togrid-template-columns: repeat(3, 1fr);, it will work as intended.2
u/MarmotOnTheRocks Jul 16 '21
I'm a dumb idiot, I didn't even think about it. This, or even adding a 5th box will make it work (with 4 columns, of course).
Thanks!
2
1
1
1
1
1
u/Wrong_Property_3392 Jul 16 '21
Wait. So now that I finally SOMEWHAT understand flex, YOU WANT ME TO LEARN GRID NOW!? 😤
1
u/i_took_your_username Jul 16 '21
Flexbox is one-dimensional (with wrapping), grid is two-dimensional.
They're useful in different ways and it's definitely helpful to know the basics of how both work
1
u/Wrong_Property_3392 Jul 16 '21
Huh. Really? So grid is kinda more advanced flexbox?
1
u/i_took_your_username Jul 16 '21
It's not more advanced exactly.
It has more functionality because it's designed to lay out elements in an extra dimension than flexbox does.
But there are definitely still times when you'd want to use flexbox, I'm not saying that grid is always "better"
1
1
1
5
u/CountSheister Jul 15 '21
Handy dandy, ty for this.
I thought the grid prefix on gap was no longer needed though?