liveBook · Manning

Flex-basis

As explained in Tiny CSS Projects

The CSS flex-basis property specifies the initial main-size contribution of a flex item before space is distributed.

flex-basis sets the initial main-size contribution of a flex item before Flexbox distributes available space. Think of it as the browser’s starting size, not always the item’s final size. section 6.7.3 section 6.9

Use flex-basis when a flex layout needs a predictable starting proportion or width:

  • Set three profile-card likes to flex-basis: 33%; with flex-shrink: 1, they can shrink evenly to account for the gaps between them. section 6.7.3
  • Give a checkout summary card flex-basis: 250px; the cart can then grow into remaining space with flex-grow: 1. section 8.5
  • Remember that flex-basis works with flex-grow and flex-shrink: the browser may adjust the starting size when available space differs. section 8.5 section 8.6

Profile likes

For three equal items inside a flex container, start each item at one-third of the available width and allow adjustment when a 12px gap makes the total too wide. section 6.7.3

Listing 6.15 Centering the likes
dl > div {
  flex-basis: 33%;
  flex-shrink: 1;
}

Inspect the compact rule that combines a percentage flex-basis with shrinking for evenly sized likes. section 6.7.3

Listing 8.29 Placing the two cards side by side on wide screens
@media (min-width: 955px) {
  .section-container {
    display: flex;
    gap: 20px;
  }
  section.my-cart { flex-grow: 1; }
  section.summary { flex-basis: 250px }
}

Inspect a responsive media-query rule that gives the summary a 250px starting width while the cart grows. section 8.5

How Tiny CSS Projects covers it

How deep it goes
Explains starting sizes and interactions with growth, shrinking, and gaps, without descending into layout-engine internals.
Examples
Uses equal profile-card likes and a responsive checkout layout with a 250px summary card.
What you can do after
Apply flex-basis in CSS to establish proportional or fixed starting sizes for flex items.
How it connects
Connects flex-basis with Flexbox, flex-grow, flex-shrink, flex-direction, flex-wrap, gaps, and media queries.

Also explained in

Compare how 5 books explain flex-basis →

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.