HTML Academy
The flex shorthand property
Flexbox, part 216/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
Multi-line flex containers and flex-grow
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Multi-line flex containers and flex-shrink

In all of the previously discussed examples, the flex container was a single line. This was appropriate, since the option to overflow flex items onto a new line is not enabled by default: flex-wrap: nowrap; is the default setting.

So, how can we grow and shrink items in a multi-line container using flex-wrap: wrap;?

The flex-shrink property works as expected in this container. However, we will not need to use it as frequently. After all, if there is not enough space in the line, the flex items will overflow onto a new line.

But if there are flex items with a basic size that is larger than the size of their flex container, then these items will be shrunk so that they can fit on a single line. This is probably the only case where flex-shrink can be used to do something useful in a multi-line container.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Multi-line flex containers and flex-shrink</title> <link href="course.css" rel="stylesheet"> <link href="style.css" rel="stylesheet"> </head> <body class="world"> <div class="spot"> <div class="skate racoon-pink"></div> <div class="skate racoon-gray"></div> <div class="skate racoon-orange"></div> </div> </body> </html>
CSS
.spot { display: flex; flex-wrap: nowrap; width: 450px; height: auto; } .skate { flex-shrink: 1; flex-basis: 100px; }

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. Increase the basic size of all skateboards to 500px.
    2. Configure flex items to overflow onto a new line in the .spot block.
    3. Then assign a shrinkage factor of zero to all skateboards.

    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.