Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Divide utilities between children using Tailwind CSS
📖 Scenario: You are creating a simple webpage section where you want to divide space evenly between child boxes inside a container. This is common when you want to show multiple items side by side with equal width.
🎯 Goal: Build a container with three child boxes that share the container's width equally using Tailwind CSS utilities.
📋 What You'll Learn
Use a container <div> with Tailwind CSS classes
Add exactly three child <div> elements inside the container
Use Tailwind CSS utilities to divide the container's width equally among the three children
Each child should have a visible border and some padding for clarity
The layout should be responsive and maintain equal widths on different screen sizes
💡 Why This Matters
🌍 Real World
Dividing space evenly between child elements is common in navigation bars, product listings, and dashboard widgets.
💼 Career
Understanding how to use Tailwind CSS flex utilities to create responsive layouts is a valuable skill for frontend web developers.
Progress0 / 4 steps
1
Create the container and three child boxes
Write HTML code to create a <div> container with three child <div> elements inside it. Each child should contain the text Box 1, Box 2, and Box 3 respectively.
Tailwind
Hint
Start by writing a container <div> and add three child <div> elements with the exact texts.
2
Add Tailwind CSS classes to the container for flex layout
Add Tailwind CSS classes flex and border to the container <div> to make it a flex container with a visible border.
Tailwind
Hint
Add class="flex border" to the container <div> to enable flex layout and show a border around the container.
3
Add Tailwind CSS classes to children to divide space equally
Add the Tailwind CSS class flex-1 to each of the three child <div> elements to make them share the container's width equally.
Tailwind
Hint
Add class="flex-1" to each child <div> so they take equal width inside the flex container.
4
Add padding and border to children for clarity
Add Tailwind CSS classes p-4 and border to each child <div> to add padding and a visible border around each box.
Tailwind
Hint
Add p-4 for padding and border for visible edges on each child box.
Practice
(1/5)
1. What does the Tailwind utility space-x-4 do when applied to a parent container with multiple child elements?
easy
A. It adds horizontal spacing of 1rem between each child element.
B. It adds vertical spacing of 1rem between each child element.
C. It adds padding of 1rem inside each child element.
D. It centers all child elements horizontally.
Solution
Step 1: Understand the space-x-4 utility
This utility adds horizontal space (margin) between direct child elements of a flex container.
Step 2: Recognize the spacing size
The number 4 corresponds to 1rem (16px by default) spacing between children horizontally.
Final Answer:
It adds horizontal spacing of 1rem between each child element. -> Option A
Quick Check:
space-x-4 = horizontal gap 1rem [OK]
Hint: Remember: space-x adds horizontal gaps between children [OK]
Common Mistakes:
Confusing space-x with vertical spacing (space-y)
Thinking it adds padding inside children
Assuming it centers children
2. Which Tailwind utility correctly applies a different background color only to the first child element inside a parent container?
easy
A. child-1:bg-blue-500
B. first:bg-blue-500
C. bg-blue-500:first
D. parent:first-child:bg-blue-500
Solution
Step 1: Identify the correct pseudo-class utility
Tailwind uses first: prefix to target the first child element.
Step 2: Confirm syntax correctness
first:bg-blue-500 applies background color blue-500 only to the first child.
Final Answer:
first:bg-blue-500 -> Option B
Quick Check:
first: prefix targets first child [OK]
Hint: Use first: prefix to style only the first child [OK]
What will be the horizontal space between Box 1 and Box 2?
medium
A. No space, boxes touch each other
B. 1rem (16px)
C. 2rem (32px)
D. 1.5rem (24px)
Solution
Step 1: Understand the space-x-6 utility
This utility adds horizontal margin of size 6 between child elements in a flex container.
Step 2: Know the spacing scale
In Tailwind, 6 corresponds to 1.5rem or 24px spacing.
Final Answer:
1.5rem (24px) -> Option D
Quick Check:
space-x-6 = 1.5rem horizontal gap [OK]
Hint: Tailwind spacing 6 = 1.5rem gap between children [OK]
Common Mistakes:
Confusing spacing scale numbers with px values
Assuming space-x adds padding inside children
Ignoring that space-x only works on flex or grid parents
4. You want to add vertical spacing between child elements but accidentally use space-x-4 on a column flex container. What is the problem?
medium
A. No vertical spacing appears because space-x adds horizontal gaps only.
B. It causes a syntax error and the page breaks.
C. It adds vertical spacing but also breaks layout.
D. It adds horizontal spacing and vertical spacing both.
Solution
Step 1: Understand flex direction and space utilities
In a column flex container, children stack vertically. space-x-4 adds horizontal gaps, which have no effect here.
Step 2: Identify correct utility for vertical spacing
To add vertical spacing, space-y-4 should be used instead.
Final Answer:
No vertical spacing appears because space-x adds horizontal gaps only. -> Option A
Quick Check:
space-x only adds horizontal gaps [OK]
Hint: Use space-y for vertical gaps, space-x for horizontal [OK]
Common Mistakes:
Expecting space-x to add vertical spacing
Thinking it causes syntax errors
Using space-x on non-flex containers
5. You want to style a list where the first child has a red border, the last child has a green border, and all other children have a blue border using Tailwind. Which combination of utilities correctly achieves this?
hard
A. first:border-red-500 last:border-green-500 border-blue-500
B. border-blue-500 first:border-red-500 last:border-green-500 !important
C. border-blue-500 first:border-red-500 last:border-green-500
D. border-blue-500 first-child:border-red-500 last-child:border-green-500
Solution
Step 1: Understand Tailwind's order of utility application
Tailwind applies utilities in order. Base border color should come first, then overrides with first: and last:.
Step 2: Check syntax correctness
first:border-red-500 and last:border-green-500 are correct pseudo-class prefixes. The base border-blue-500 applies to all children.
Step 3: Identify incorrect options
first:border-red-500 last:border-green-500 border-blue-500 applies base border last, which overrides first/last styles. border-blue-500 first:border-red-500 last:border-green-500 !important uses invalid !important. border-blue-500 first-child:border-red-500 last-child:border-green-500 uses invalid selectors.
Final Answer:
border-blue-500 first:border-red-500 last:border-green-500 -> Option C
Quick Check:
Base first, then first:/last: overrides [OK]
Hint: Apply base styles first, then use first:/last: to override [OK]