CSS Grid
Vertical Positioning of Elements with
align-items and align-content
The CSS property align-items is for vertical positioning of the items in a grid. Below are all the options, together with the code required for each.
- The property align-items can have any of the following four values:
- The property align-content can have any of the following three values:
Left cell
Middle cell
Right cell
HTML
CSS
align-items: start;
Left cell
Middle cell
Right cell
HTML
CSS
align-items: center;
Left cell
Middle cell
Right cell
HTML
CSS
align-items: end;
Left cell
Middle cell
Right cell
HTML
CSS
align-items: stretch;
Effect: items occupy 100% of the row height.
Vertically
centred
content
Make grid items occupy the full height available
and vertically center their contents.
HTML
Note: you must add nested divs within each cellCSS
align-items: stretch;
Note: you must define classes for the nested divs. Vertically centered positioning is achieved using
CSS Flexbox with the property
align-items.
Vertically
+horizontally
centred content
Make grid items occupy the full height and width available
and vertically and horizontally center their contents.
HTML
Note: you must add nested divs within each cellCSS
align-items: stretch;
Note: you must define classes for the nested divs. This centered positioning is achieved using
CSS Flexbox with the properties:
-
horizontal positioning:
justify-content: center; -
vertical positioning:
align-items: center;
Top cell
Middle cell
Bottom cell
HTML
CSS
align-content: space-evenly;
Note: this property is used to define the vertical space between items; grid-gap is not used as
align-content
automatically creates a gap of the appropriate size.
Effect: Equal space between elements plus at the top and bottom of the column.
Top cell
Middle cell
Bottom cell
HTML
CSS
align-content: space-between;
Notes: this property is used to define the vertical space between items; grid-gap is not used as
align-content automatically creates a gap of the appropriate size.
Effect: Equal space between elements with no space at either the top or bottom of the column.
Left cell
Middle cell
Right cell
HTML
Key CSS:
align-content: space-around;
Note: this property is used to define the vertical space between items; grid-gap is not used as
align-content automatically creates a gap of the appropriate size.
Effect: Equal space between elements with half that space at each end of the row.