HTML Academy
The item shrinkage factor, flex-shrink
Flexbox, part 211/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
Calculating the total size with flex-shrink
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Shrinking items proportionally

The flex-shrink property is very similar to the flex-grow property. It is used to assign the proportions by which flex items “absorb” negative space.

The greater the value of the shrinkage factor for this item, the more negative space it will absorb and the more the item will be shrunk.

When the basic sizes of flex items are the same, the shrinkage proportions for elements are considered to be the same as the growth proportions. If the basic sizes of flex items differ, then use of this mechanism can be complicated. We will explore it in more detail in the next assignment.

In the meantime, experiment again with the factors in the puzzle assignment.

You need to select the right values for flex-shrink so that the total sizes of the items match the ones for the brown and green bars and nothing appears above the red bar.

The red bar is used to display the negative space size that is distributed when shrinking the flex items.

You will recognize the basic sizes of the items and flex container sizes from the code.

Hint: to achieve the simplest solution, you need factors that are integers of no more than 5.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Shrinking items proportionally</title> <link href="course.css" rel="stylesheet"> <link href="style.css" rel="stylesheet"> </head> <body class="world world-flat"> <div class="spot"> <div class="skate no-width racoon-green"></div> <div class="skate no-width racoon-brown"></div> <div class="ruler ruler-green w-200">200px</div> <div class="ruler ruler-brown w-100 l-200">100px</div> <div class="ruler ruler-negative w-200 l-300">−200px</div> </div> </body> </html>
CSS
.spot { display: flex; margin-left: 30px; padding: 10px 0; width: 300px; height: 200px; } .racoon-green { flex-shrink: 0; flex-basis: 250px; } .racoon-brown { flex-shrink: 0; flex-basis: 250px; }

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 flex-shrink values to the raccoons so that their width is equal to the width of the bars.

    In this assignment you can only change the values of flex-shrink,

    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.