topskill.dev
CoursesTracks
0
All courses/CSSWrapping and Flex Items
Flexbox
7 / 11
← CSS
○CSS Rule Style an Exhibit Card○Write Your First CSS Rule○CSS Selectors Target Exhibit Details○Target Exhibit Details○Apply CSS Three Sources○Apply CSS Three Ways○Specificity Resolve a Style Conflict○Resolve Specificity○Inheritance and the cascade✦Module Quiz
○Color Palette○Color Palette○Background Layer○Background Layer○Type Rhythm○Type Rhythm○Borders and Shadows○Borders and Shadows✦Module Quiz
○Box Model Seed Packet Card○Space a Seed Packet○Display Swap Table Labels○Arrange Swap Table Labels○Positioning Pickup Pin○Pin the Pickup Location○Sizing and Overflow○Size a Seed-Swap Notice○Sticky scroll headings✦Module Quiz
○Advanced Selectors Book Cart Sign○Target a Book Cart Sign○Pseudo-Classes Night Cart States○Style Night Cart States○Pseudo-Elements○Add a Book-Quote Mark✦Module Quiz
○Lantern Market navigation○Lantern Market navigation✦Module Quiz
○Community garden request card○Community garden request card✦Module Quiz
○Flex Direction○Flex Direction○Main-Axis Spacing○Main-Axis Spacing○Cross-Axis Alignment○Cross-Axis Alignment●Wrapping and Flex Items○Wrapping and Flex Items○Flexbox Navigation○Flexbox Navigation✦Module Quiz
○Grid Tracks○Grid Tracks○Grid Gaps○Grid Gaps○Grid Placement○Grid Placement○Responsive Grid○Responsive Grid✦Module Quiz
○River radio schedule○Harbor radio schedule✦Module Quiz
○Field note color system○Field note color system○Transforms○Rotate a Field Note○Resilient styles✦Module Quiz
○Kite festival signal○Garden festival signal✦Module Quiz
○Garden forecast○Harbor forecast○Fluid sizing○Fluid weather bulletin○Images that fit✦Module Quiz
○Seed inventory table○Tool checkout table✦Module Quiz
○Community maker profile○Maker profile sheet✦Module Quiz

Wrapping and Flex Items

Let supply cards move to another line

A flex container uses nowrap by default. Its items try to fit one line, often shrinking as the row gets narrower. flex-wrap: wrap on .supply-row lets the browser start another line instead.

Wrapping and item sizing are separate decisions. This example puts flex: 1 1 9rem on .card, because flex describes each item rather than the container. The three values mean:

  • flex-grow: 1: the card can take a share of spare room on its line. These cards have equal grow values, so they receive equal shares.
  • flex-shrink: 1: the card may shrink when a line is too small, subject to its content's minimum size.
  • flex-basis: 9rem: start the sizing calculation from a 9rem main-axis size. This is not a fixed final width.

A flex item’s automatic minimum can stop it shrinking below a long unbroken label. For content that may wrap, min-width: 0 on the item and overflow-wrap: anywhere on its text can let the box and words shrink together. Do not hide important text merely to make a row fit.

The supplied cards use the default content-box sizing, so their padding is added outside that basis. The gaps also take space. That is why three cards may need another line even when three lots of 9rem seem to fit.

Run Preview at a wide and a narrow width. Each line shares its own free space: a card alone on the last line grows across that line. Temporarily change wrap to nowrap and notice the cards squeeze onto one line. Restore wrap, then try a 6rem basis to see more cards fit. Restore 9rem afterward.

Hint 1
1 / 2
HINT 1

Open style.css and change one declaration at a time.

HINT 2

Run Preview after each change; restore the value before the exercise.

Files
  • ⋄index.html
  • ⋄style.css
Loading editor…