HTML CSS Bootstrap JavaScript jQuery MySQL PHP Data Mining

Flex Grow & Shrink

Most flexbox utilities (like .justify-content) are applied directly to the outer parent container. However, the Grow and Shrink classes are unique. You apply them selectively to individual child elements to control exactly how those specific items fight for space within the row!


Flex Grow (.flex-grow-1)

By default, flex items are totally passive; they only take up exactly as much space as their inner content demands. If you apply .flex-grow-1 to a child item, you command it to become aggressive and mathematically consume every last pixel of empty space remaining in the container until it hits the wall!

If you apply .flex-grow-1 to multiple items simultaneously, they will negotiate and divide the leftover empty space equally among themselves.

1. Default Behavior (No Growth)

Notice all the dead empty space sitting on the right side.

Box 1
Box 2
Box 3
2. Center Box with .flex-grow-1

Box 2 devours all the empty space dynamically!

Box 1
Box 2 (.flex-grow-1)
Box 3
3. All Boxes with .flex-grow-1

They all fight for space, automatically becoming perfectly equal widths!

Box 1
Box 2
Box 3
<!-- A classic search bar layout. The input grows to fill the gap, the button stays fixed! -->
<div class="d-flex">
    <input type="text" class="flex-grow-1 form-control" placeholder="Search...">
    <button class="btn btn-primary">Go</button>
</div>

Flex Shrink (.flex-shrink-0)

Bootstrap sets all flex elements to naturally shrink (using flex-shrink: 1) when space runs out horizontally. This prevents items from bleeding out of the container when the screen gets narrow.

However, what if you have a vital icon or button that absolutely must never be compressed under any circumstances? You can armor the element by giving it the .flex-shrink-0 class. This explicitly prevents the browser from making it smaller, forcing everything else around it to shrink instead.

1. Default Behavior (Allow Shrinking)

The large text block on the left violently forces the second block to shrink its text into an ugly vertical tower.

massive paragraph describing the product perfectly that takes up extreme room and crushes everything
I am shrinking
2. Preventing Shrinkage (.flex-shrink-0)

The second box refuses to yield its native padding structure, forcing the large paragraph to adapt instead!

massive paragraph describing the product perfectly that takes up extreme room and crushes everything
I refuse to shrink!
<!-- The text paragraph can be safely compressed, but the vital checkout button refuses to shrink! -->
<div class="d-flex">
    <p class="w-100">Gigantic amount of user description text...</p>
    <button class="btn btn-warning flex-shrink-0">Checkout</button>
</div>