HTML Academy
The flow direction of the main axis and margins
Flexbox, part 25/28
Back to the list of tasks
  • 1. Flex items and the block model
  • 2. Features of the margin property
  • 3. Alignment and margins
  • 4. The flow direction of the main axis and margins
  • 5. The initial main size of flex item, flex-basis
  • 6. Test: Cubism
  • 7. The item growth factor, flex-grow
  • 8. Growing items proportionally
  • 9. Calculating the total size with flex-grow
  • 10. The item shrinkage factor, flex-shrink
  • 11. Shrinking items proportionally
  • 12. Calculating the total size with flex-shrink
  • 13. flex-shrink and min-width
  • 14. Test: Mastering factors
  • 15. The flex shorthand property
  • 16. Multi-line flex containers and flex-shrink
  • 17. Multi-line flex containers and flex-grow
  • 18. flex-basis: 100% and flex-wrap
  • 19. The heading with description in flexboxes
  • 20. Heading with description, part 2
  • 21. Flexible menu with overflowing content
  • 22. Flexible menu with overflow, part 2
  • 23. Input fields with dynamic width
  • 24. The course card
  • 25. Course card, part 2
  • 26. Course card, part 3
  • 27. So many cards
  • 28. Test: Flexible flows
Test: Cubism
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

The initial main size of flex item, flex-basis

You can see from the example of the margins that the “old” properties inside the flex container behave rather stupidly. The width and height properties are also unable to react to the rotation of the main axis. Therefore, the concepts of the main size and cross size have been introduced.

If the main axis flows horizontally, then the main size is the width property, and the cross size is the height property. If the main axis flows vertically, then the opposite is true.

It would be nice to have a “smart” property that could be used to assign the size of flex elements that knows about the flow direction of the main axis and “rotates” with it.

Indeed, we already have such a property: flex-basis. It sets the basic size of the flex item or size along the main axis.

If the flex-basis is not set, or its value is auto, then the basic size is taken from width or height.

The flex-basis property accepts the same values as width/height:

flex-basis: 100px; /* basic size of 100 pixels */
flex-basis: 50%;   /* basic size of 50% of the container */

The flex-basis takes precedence over the width and height properties, and if all three properties are assigned for the flex item, then flex-basis will override the width or height properties depending on the flow direction of the main axis.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>The initial main size of flex item, flex-basis</title> <link href="course.css" rel="stylesheet"> <link href="style.css" rel="stylesheet"> </head> <body class="world"> <div class="spot"> <div class="skate racoon-orange"></div> </div> </body> </html>
CSS
.spot { display: flex; flex-direction: row; align-items: center; justify-content: center; } .racoon-orange { }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0
    1. Assign a width of 300px and a height of 100px to the Orange Raccoon’s skateboard.
    2. Then assign it the basic size of 100%.
    3. Then change the flow direction of the .spot main axis to column.

      Notice how the width and height change when the axis is rotated due to the basic size that we assigned.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.