📖 Scenario: You are creating a simple responsive card layout for a website. The cards should adjust their size inside a flex container depending on available space. You will use Tailwind CSS flex grow and shrink utilities to control how the cards expand or shrink.
🎯 Goal: Build a flex container with three cards. Use Tailwind CSS classes to make the first card grow to fill extra space, the second card stay fixed size, and the third card shrink if needed.
📋 What You'll Learn
Create a flex container using Tailwind CSS
Add three child div cards inside the container
Use flex-grow and flex-shrink Tailwind classes to control card resizing
Make the first card grow to fill extra space
Make the second card fixed size (no grow or shrink)
Make the third card shrink if space is limited
💡 Why This Matters
🌍 Real World
Flex grow and shrink are used in responsive web layouts to control how elements resize when the browser window changes size.
💼 Career
Understanding flex grow and shrink is essential for front-end developers to build flexible, user-friendly interfaces that adapt to different devices.
Progress0 / 4 steps
1
Create the flex container and three cards
Create a <div> with Tailwind classes flex and border to act as the container. Inside it, add three child <div> elements with Tailwind classes border, p-4, and text content exactly Card 1, Card 2, and Card 3 respectively.
Tailwind
Hint
Use flex on the container to arrange children horizontally. Add borders and padding to cards for visibility.
2
Make the second card fixed size
Add the Tailwind classes w-32 and flex-shrink-0 to the second card's <div> to fix its width to 8rem (128px) and prevent shrinking.
Tailwind
Hint
Use w-32 and flex-shrink-0 to set a fixed width that doesn't shrink on the second card.
3
Make the first card grow to fill extra space
Add the Tailwind class flex-grow to the first card's <div> so it expands to fill available space in the container.
Tailwind
Hint
Use flex-grow on the first card to let it expand.
4
Make the third card shrink if needed
Add the Tailwind class flex-shrink to the third card's <div> so it can shrink when the container is too small.
Tailwind
Hint
Use flex-shrink on the third card to allow it to shrink.
Practice
(1/5)
1. What does the Tailwind class flex-grow-0 do to a flex item?
easy
A. Prevents the item from growing to fill extra space
B. Makes the item grow to fill all extra space
C. Prevents the item from shrinking when space is tight
D. Makes the item shrink faster than others
Solution
Step 1: Understand flex-grow property
The flex-grow property controls how much a flex item can grow relative to others when extra space is available.
Step 2: Interpret the class flex-grow-0
The class flex-grow-0 sets flex-grow to 0, meaning the item will not grow to fill extra space.
Final Answer:
Prevents the item from growing to fill extra space -> Option A
Quick Check:
flex-grow-0 means no growth [OK]
Hint: flex-grow-0 means no growth, flex-grow-1 means grow [OK]
Common Mistakes:
Confusing grow with shrink
Thinking flex-grow-0 allows growth
Mixing flex-grow with flex-shrink
2. Which Tailwind class correctly prevents a flex item from shrinking?
easy
A. flex-grow-1
B. flex-grow-0
C. flex-shrink-1
D. flex-shrink-0
Solution
Step 1: Understand flex-shrink property
The flex-shrink property controls how much a flex item shrinks when space is limited.
Step 2: Identify the class that disables shrinking
The class flex-shrink-0 sets flex-shrink to 0, preventing the item from shrinking.
Final Answer:
flex-shrink-0 -> Option D
Quick Check:
flex-shrink-0 means no shrinking [OK]
Hint: Use flex-shrink-0 to stop shrinking, flex-shrink-1 to allow [OK]
But the second div overflows the container. What is the problem?
medium
A. flex-shrink on second div prevents shrinking, causing overflow
B. w-24 is too small for both divs, causing overflow
C. flex-shrink-0 on first div prevents it from shrinking, causing overflow
D. Missing flex-grow classes causes overflow
Solution
Step 1: Check widths and container size
Container width is 40. Both divs have width 24, total 48, which is more than container.
Step 2: Analyze flex-shrink classes
First div has flex-shrink-0, so it cannot shrink below 24. Second div has default shrink, so it tries to shrink but can't reduce enough to fit container.
Final Answer:
flex-shrink-0 on first div prevents it from shrinking, causing overflow -> Option C
Thinking flex-shrink on second div causes overflow
Ignoring container width limits
Assuming flex-grow affects shrinking
5. You want three flex items inside a container to share leftover space proportionally: the first twice as much as the second, and the third does not grow. Which Tailwind classes should you use?
hard
A. First: flex-grow-2, Second: flex-grow-1, Third: flex-grow-0
B. First: flex-grow, Second: flex-grow-2, Third: flex-grow-0
C. First: flex-grow-1, Second: flex-grow-2, Third: flex-grow-0
D. First: flex-grow-0, Second: flex-grow-1, Third: flex-grow-2
Solution
Step 1: Understand proportional growth with flex-grow
Flex-grow values determine how leftover space is divided. A value of 2 means twice the space compared to 1.
Step 2: Assign classes to match proportions
First item needs flex-grow-2, second flex-grow-1, third flex-grow-0 to not grow.
Final Answer:
First: flex-grow-2, Second: flex-grow-1, Third: flex-grow-0 -> Option A
Quick Check:
flex-grow values set proportional growth [OK]
Hint: Use flex-grow numbers to set proportional growth [OK]
Common Mistakes:
Using wrong grow numbers or order
Assigning flex-grow-0 to growing items
Confusing grow with shrink classes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.