Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Columns

Next comes the hero. Its headline, text and link are one below another, but the headline and the text touch. Let's make the hero a flex container in a column: then we can space its items with gap, and later in this lesson, center them.

The direction of the main axis (the property flex-direction) is set by these classes:

ClassCSSDirection
flex-rowflex-direction: row;a row from left to right (the default)
flex-colflex-direction: column;a column from top to bottom
flex-row-reverseflex-direction: row-reverse;a row from right to left
flex-col-reverseflex-direction: column-reverse;a column from bottom to top

Careful: flex-col only says which way the items go. The container also needs the class flex; without it, it isn't a flex container at all.

As you know from the CSS course, the axes turn with the direction. In a column, the main axis goes from top to bottom and the cross axis from left to right. So in a column, justify-* moves the items up and down, and items-* moves them to the left and right.

Instructions

  1. 1

    Add the classes flex flex-col to the hero (the section with the orange background). The items are one below another, as before, but look at the link: it's now as wide as the whole hero. In a column, the cross axis goes from left to right, and flex items stretch along it (items-stretch is the default). As a flex item, the link is laid out as a block, so its inline-block no longer matters.

  2. 2

    Add the class gap-4. The headline, the text and the link move 16 px apart.

  3. 3

    Add the class items-start. The items are no longer stretched: each one is only as wide as its content needs, at the start of the cross axis, which is on the left.

Back

4/11

  1. 1. Display
  2. 2. Flexbox
  3. 3. Justify and Align
  4. 4. Columns
  5. 5. Wrapping and Growing
  6. 6. Grid
  7. 7. Spanning Columns
  8. 8. Centering
  9. 9. Badges on Cards
  10. 10. A Sticky Header
  11. 11. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.