topskill.dev
CoursesTracks
0
All courses/CSSFlex Direction
Flexbox
1 / 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

Flex Direction

Put the trail kit in a row

Without a layout rule, the three cards would be ordinary block elements stacked one below another. display: flex on .kit-row changes how that section arranges its direct children: Map, Snacks, and First aid become flex items. Put the layout rule on their parent, not on each card.

Flexbox works along two directions, called axes. The main axis follows flex-direction. With row, these English, left-to-right cards run across the page. With column, they run down the page. The cross axis is perpendicular to the main axis, so it changes too. “Main” does not always mean horizontal.

In style.css, gap: 1rem leaves space between the cards. A rem is based on the root element's font size; with the usual 16px default, this gap is 16px. Unlike padding, it does not create space inside a card.

Run Preview. Find .kit-row, change flex-direction: row to column, and run it again. The order stays Map, Snacks, First aid, but the main axis now points down. The cards stretch across the available width because that is the default cross-axis alignment. Restore row before the exercise.

Learn more

MDN's Flexbox guide is a useful reference when you want to compare the alignment options.

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…