Flexbox Not Working? min-width: 0 and Other Surprises

Text that will not shrink, items that overflow, and margins that act strange. Why min-width: auto causes most Flexbox bugs and how to fix them.

Related chapters

Keep learning

Overview

Chapter 08 · flexbox Flexbox results that look like bugs The previous chapter is the happy path. These are the same properties, doing what the spec says, in the cases that surprise a React layout.

1. flex: 1 is not flex-grow: 1

The shorthand sets three values. flex: 1 means grow 1, shrink 1, basis 0%. flex-grow: 1 on its own leaves the basis at auto, which is the width of the content.

On the main axis

flex-basis is the main size. width is only a fallback, and only when the basis is auto. In a column, the same pair is flex-basis and height.

2. An auto margin eats justify-content

Free space on the main axis can go to justify-content or to an auto margin. The auto margin takes it first.

3. Stretch loses to a set cross size

The default align-items is stretch. A height on a row item, or a width on a column item, is a cross size, and stretch steps aside.

4. A column will not shrink below its text

The dashed frame is the height you wanted. The body is a flex item, so its minimum is the height of the notes. Give the shell a height, then min-height: 0 and overflow: auto on the body. The header and Save stay put, and the notes scroll.

5. An image’s file size is a minimum

The same minimum that blocked the long word blocks a picture. The item will not get narrower than the image’s intrinsic width until you say it may.

6. Loose text becomes an item

Whitespace between tags is ignored. A word next to an element is not. Flexbox wraps that word in an anonymous item. A sidebar, a modal, and a panel beside the chat all fail the same way: the middle grows the page instead of scrolling. The shell needs a height from its parent. The scrolling child needs min-height: 0. A toolbar that pins one button uses margin-left: auto, not a new justify value.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
  • System Design — Core concepts first (SQL vs NoSQL, CAP, indexing, replication, sharding), then designs grouped by what carries them: the database, Redis, Kafka, or many services.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.