liveBook · Manning

Shrink

As explained in Web Design Playground

A flexbox sizing behavior that determines how a flex item reduces in size when space is limited.

What happens when flex items need more room than their container has? They can shrink to fit. The `flex-shrink` property lets you control which items give up space—and which keep their size. section 12.6

Give an item a `flex-shrink` value to guide what happens when space runs short:

  • `1` is the default. All items with this value are treated equally when the browser calculates shrinkage. section 12.6
  • A value above `1` makes an item shrink more; a value between `0` and `1` makes it shrink less. A value of `0` prevents it from shrinking. section 12.6

Keep a thumbnail its size

Picture a list item with an image beside some text. Make the list item a flex container, set `.dictionary-image { flex-shrink: 0; }`, and give the text `flex-grow: 1`. The thumbnail keeps its size while the text uses the remaining room. section 12.8 section 12.9

One small catch: a larger shrink value cannot force an item below the minimum size needed to display its content. Items that start at different widths also shrink by different amounts; their initial widths matter to the calculation. section 12.6

Try changing the thumbnail’s `flex-shrink` from `0` to `1`, then narrow its container. For a flexible page layout, `flex-shrink: 0` can also work with `flex-basis` to preserve minimum block widths while `flex-wrap` allows blocks to move onto another line. section 12.6 section 13.9

How Web Design Playground covers it

How deep it goes
Explains default and custom values, initial-width effects, and content minimums without working through the shrinkage math.
Examples
Uses a thumbnail-and-text list and a header logo that must not shrink.
What it assumes
Assumes familiarity with CSS rules and flex items while explaining flex-shrink values from their default upward.
What you can do after
Build it from scratch: create a flexbox thumbnail list whose image does not shrink while its text uses remaining space.
How it connects
Connects flex-shrink with flex-grow, flex-basis, and flex-wrap in item sizing and flexible layouts.

Also explained in

Compare how 4 books explain shrink →

Related concepts

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