Flexbox
Build one-dimensional layouts with deliberate wrapping, alignment, and flexible sizing.
Flexbox distributes items along a main axis and aligns them on a cross axis. It works best when one direction drives the layout: a navigation row, button group, media object, or card footer. Let items wrap when space is genuinely limited.
See the core pattern
Read this rule set from the outside in. Identify the inputs, the decision or transformation, and the result before changing it.
.actions {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: .75rem;
}
.actions__primary { margin-inline-start: auto; }
.actions > * { flex: 0 1 auto; }Working rules
- Identify the main and cross axes
- Use gap instead of margins between siblings
- Test long labels and zoom before forcing no-wrap
A common mistake
justify-content and align-items change meaning when flex-direction changes. Always reason from the current axes.
Guided practice
Push one action to the logical end of a row without spacing every item apart.
- Copy the example into the editable notebook below.
- Change one thing at a time and keep the program or rule valid.
- Explain the result in one sentence without relying on jargon.