CSS Grid
.grid-container
.grid-containerThe main class container
display: grid is the main property needed here
grid-template-columns
grid-template-columnslayout of columns horizontally
grid-template-columns: 1fr 1fr 1fr has 3 columns, each one is 1fr
A shorthand would be grid-template-columns: repeat(3, 1fr);
grid-template-rows
grid-template-rowsis the same as grid-template-columns only vertically
justify-items
justify-itemsHow grid pieces are aligned horizontally
justify-items: strech; is default and takes up full width of the columns justify-items: center; centers grid items justify-items: start; pushes grid items to the left justify-items: end; pushes grid items to the right
IMPORTANT
To justify individual grid items, you must use justify-self
justify-self: end; will align grid item to the bottom of it's grid area
align-items
align-itemsLike justify-items but vertical
IMPORTANT
align-self for vertical alignment of grid items
gap is the gap between grid items
gap is the gap between grid itemsgap: 10px;
Grid Items
grid-column
grid-columnHelps lay out the grid
grid-column: 1 / span 2; will make this grid item 1 column and span 2 column spaces
See image and code below

Last updated
Was this helpful?