Techie February 2022
Definition
The CSS Grid layout uses rows and columns to position elements on a web page without having to use floats.
It is an alternative to flexbox but most developers agree that the grid is more suitable for the general layout while flexbox is more effective when you narrow down to smaller layouts within the main layout.
1 . Set display to grid.
2 . Declare your columns or rows using grid-template-column/row.
3 . Use the fraction unit fr to divide columns or rows equally.
4 . Use grid-auto-flow instead of grid-template-column/grid-template-rows if you want the width to auto-adjust depending on the number of columns or rows.
5 . Use grid-auto-flow with media queries to change the direction of the elements e.g from columns to rows whenever the screen size gets smaller.
6 . Use grid gap to space the elements instead of margins.
7 . No need to declare grid-template-row. Unless you absolutely have too, leave it out, let it be implicit. This will help you reduce the overheads incase you add more columns than you declared.
8 . Use span to extend columns or rows.
9 . Re-position elements within the grid using grid-column-start, grid-column-end and the nth-child properties.
Thanks for reading, see you in the next one!