CSS Grid

.grid-container

The main class container

display: grid is the main property needed here

grid-template-columns

layout 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

is the same as grid-template-columns only vertically

justify-items

How 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

Like justify-items but vertical

IMPORTANT

align-self for vertical alignment of grid items

gap is the gap between grid items

gap: 10px;


Grid Items

grid-column

Helps 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


css grid

Last updated

Was this helpful?