liveBook · Manning

Align-items

As explained in Tiny CSS Projects

The CSS align-items property controls the alignment of grid or flex items along the relevant cross axis.

Want a card to sit in the middle of the page? Make its parent a flex container, then put `align-items: center` on that parent to center the card vertically. Use `justify-content: center` alongside it to center the card horizontally. section 6.4

Listing 6.5 Centering the card
body {
  ...
  display: flex;
  justify-content: center;    #1
  align-items: center;        #2
}

The `body` rule shows both declarations on the parent of the card: `align-items` handles vertical alignment here, while `justify-content` handles horizontal positioning. section 6.4

`align-items` also works when you do not want centering. Flex items stretch by default, which can make items of different heights match the tallest one. On a credit card’s top row, `align-items: flex-start` keeps their tops aligned instead. section 9.2.2

A few small layouts show where the declaration belongs:

  • For a grid-based summary card, `align-items: center` helps center the paragraph within its middle row. Removing the heading’s bottom margin keeps the surrounding whitespace balanced. section 5.4.2
  • For a fixed-height security-code band, `align-items: center` centers the text vertically; `justify-content: flex-end` keeps it on the right. section 9.2.3
  • For a share button, `align-items: center` aligns its icon and text vertically, while `gap` adds space between them. section 11.5.1

How Tiny CSS Projects covers it

How deep it goes
Works through CSS declarations in several layouts and explains stretch versus flex-start, without exploring browser layout internals.
Examples
Uses a centered profile card, a grid-based summary card, a credit-card security-code band, and an icon-and-text button.
What it assumes
Introduces `display: flex` on the parent before applying alignment; assumes familiarity with basic HTML elements and CSS rules.
What you can do after
Operate/configure it to center content, align flex items at their tops, or avoid unwanted stretching.
How it connects
Connects align-items to Flexbox, CSS Grid, justify-content, grid-template-rows, and gap.

Also explained in

Compare how 4 books explain align-items →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.