📖 Scenario: You are creating a simple responsive card layout for a website. Each card should have a fixed base size but also be flexible to grow or shrink depending on the screen size.
🎯 Goal: Build a row of three cards using Tailwind CSS. Each card should have a flex basis of 1/3 of the container width and be able to grow or shrink as needed.
📋 What You'll Learn
Use a flex container to hold the cards
Set the flex basis of each card to one-third of the container width using Tailwind classes
Allow the cards to grow and shrink with flex-grow and flex-shrink
Add simple styling so cards are visible with background color and padding
Ensure the layout is responsive and cards adjust on smaller screens
💡 Why This Matters
🌍 Real World
Flexbox layouts are common in web design to create flexible, responsive interfaces that adjust to different screen sizes.
💼 Career
Understanding flex basis and sizing with Tailwind CSS is important for front-end developers building modern, responsive websites quickly and efficiently.
Progress0 / 4 steps
1
Create the HTML structure with a flex container and three cards
Write the HTML code to create a <div> with class flex as the container. Inside it, add three <div> elements each with the class card. This sets up the basic structure for the cards.
Tailwind
Hint
Use a <div> with class flex for the container. Then add three child <div> elements with class card.
2
Add Tailwind classes to set flex basis to one-third for each card
Add the Tailwind class basis-1/3 to each card div to set their flex basis to one-third of the container width.
Tailwind
Hint
Use the Tailwind class basis-1/3 on each card to set their base size to one-third of the container.
3
Allow cards to grow and shrink with flex-grow and flex-shrink classes
Add the Tailwind classes grow and shrink to each card div so they can grow and shrink as needed inside the flex container.
Tailwind
Hint
Add grow and shrink classes to each card so they can resize flexibly.
4
Add background color and padding for visibility and responsiveness
Add Tailwind classes bg-blue-200 and p-4 to each card div to give them a light blue background and padding. Also add flex-wrap to the container so cards wrap on smaller screens.
Tailwind
Hint
Add bg-blue-200 and p-4 to each card for color and spacing. Add flex-wrap to the container so cards wrap on small screens.
Practice
(1/5)
1. What does the Tailwind class basis-1/3 do in a flex container?
easy
A. Makes the flex item grow to fill one-third of the container
B. Sets the initial size of the flex item to one-third of the container's main size
C. Prevents the flex item from shrinking below one-third of its size
D. Sets the flex item to always be exactly one-third of the container width regardless of content
Solution
Step 1: Understand flex basis meaning
Flex basis sets the starting size of a flex item before growing or shrinking.
Step 2: Interpret basis-1/3 in Tailwind
This class sets the flex basis to one-third of the container's main size, not forcing exact size but initial size.
Final Answer:
Sets the initial size of the flex item to one-third of the container's main size -> Option B
Quick Check:
Flex basis = initial size = one-third [OK]
Hint: Flex basis sets start size, not final size [OK]
Common Mistakes:
Confusing basis with grow or shrink
Thinking basis fixes size exactly
Assuming basis prevents shrinking
2. Which of the following is the correct Tailwind class to set a flex item's basis to 16rem?
But the items overflow the container width. What is the main reason?
medium
A. The sum of basis sizes (2/3 + 1/2) exceeds 1, causing overflow
B. Missing flex-grow classes to allow shrinking
C. Tailwind does not support fractional basis classes
D. The container needs flex-wrap to prevent overflow
Solution
Step 1: Calculate the sum of basis fractions
2/3 + 1/2 = 4/6 + 3/6 = 7/6 > 1.
Step 2: Understand the effect
When the sum of flex-basis values exceeds 1, it causes the flex items to overflow the container.
Final Answer:
The sum of basis sizes (2/3 + 1/2) exceeds 1, causing overflow -> Option A
Quick Check:
Sum of basis fractions > 1 causes overflow [OK]
Hint: Check if basis fractions sum over 1 for overflow [OK]
Common Mistakes:
Assuming basis fractions always fit container
Ignoring default flex shrink behavior
Confusing grow with shrink effects
5. You want three flex items inside a container to have these widths initially: 25%, 50%, and 25%. You also want the middle item to grow twice as fast as the others when space is available. Which Tailwind classes correctly achieve this?
hard
A. basis-1/4 grow, basis-1/2 [flex-grow:2], basis-1/4 grow
B. basis-1/4 flex-grow-1, basis-1/2 flex-grow-2, basis-1/4 flex-grow-1
C. basis-1/4 grow, basis-1/2 grow [flex-grow:2], basis-1/4 grow
D. basis-1/4 grow, basis-1/2 grow, basis-1/4 grow
Solution
Step 1: Set correct basis classes
Use basis-1/4 for 25% and basis-1/2 for 50% widths.
Step 2: Apply grow classes
Tailwind uses grow for flex-grow:1 and [flex-grow:2] for flex-grow:2.
Step 3: Assign grow classes to items
First and third items get grow, middle item gets [flex-grow:2] to grow twice as fast.
Final Answer:
basis-1/4 grow, basis-1/2 [flex-grow:2], basis-1/4 grow -> Option A
Quick Check:
Use grow and [flex-grow:2] with basis fractions [OK]
Hint: Use grow and [flex-grow:2] classes for different grow rates [OK]
Common Mistakes:
Using non-existent flex-grow-1 class
Combining grow and grow-2 on same element
Forgetting to set basis sizes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.