📖 Scenario: You are building a simple webpage section that shows three colored boxes side by side. To arrange these boxes horizontally, you need to activate the flex container using Tailwind CSS.
🎯 Goal: Create a container that uses Tailwind CSS flexbox utilities to display three colored boxes in a row with equal spacing.
📋 What You'll Learn
Use Tailwind CSS classes to create a flex container
Add three boxes inside the container with distinct background colors
Ensure the boxes are arranged horizontally side by side
Use semantic HTML elements and accessible attributes
💡 Why This Matters
🌍 Real World
Flexbox is a common way to arrange items horizontally or vertically in web layouts. Activating a flex container is the first step to using this powerful layout tool.
💼 Career
Web developers often use Tailwind CSS to quickly build responsive and accessible layouts. Knowing how to activate and control flex containers is essential for modern frontend development.
Progress0 / 4 steps
1
Create the container and boxes
Write the HTML code to create a <section> element with the class container. Inside it, add three <div> elements with the classes box1, box2, and box3 respectively. Each box should have text content: Box 1, Box 2, and Box 3.
Tailwind
Hint
Start by creating a <section> with class container. Then add three <div> elements inside it with the correct classes and text.
2
Add Tailwind flex container class
Add the Tailwind CSS class flex to the <section> element with class container to activate the flex container.
Tailwind
Hint
To make the container a flex container, add the class flex alongside container in the <section> tag.
3
Add background colors and spacing to boxes
Add Tailwind CSS classes to the boxes: bg-red-400 to box1, bg-green-400 to box2, and bg-blue-400 to box3. Also add p-4 for padding and m-2 for margin to each box.
Tailwind
Hint
Use Tailwind classes bg-red-400, bg-green-400, bg-blue-400 for colors, and p-4 and m-2 for padding and margin on each box.
4
Make the container responsive and accessible
Add the Tailwind class justify-center to the <section> element to center the boxes horizontally. Also add aria-label="Color boxes container" to the <section> for accessibility.
Tailwind
Hint
Center the boxes by adding justify-center to the container's class list. Add aria-label="Color boxes container" for screen readers.
Practice
(1/5)
1. What does adding the Tailwind class flex to a container do?
easy
A. It activates the flexbox layout on that container.
B. It hides the container from view.
C. It adds a fixed width to the container.
D. It changes the container's background color.
Solution
Step 1: Understand the role of the flex class
The flex class in Tailwind activates the flexbox layout on the container, enabling flexible arrangement of child items.
Step 2: Compare other options
Other options describe unrelated effects like hiding, fixed width, or color change, which flex does not do.
Final Answer:
It activates the flexbox layout on that container. -> Option A
Quick Check:
Adding flex = activates flexbox [OK]
Hint: Remember: flex turns on flexbox layout [OK]
Common Mistakes:
Thinking flex hides the container
Confusing flex with width or color classes
Assuming flex only styles text
2. Which of the following is the correct Tailwind syntax to activate flexbox on a container?
easy
A. flex
B. flexbox
C. flex-container
D. flex-layout
Solution
Step 1: Recall Tailwind's flexbox activation class
The correct class to activate flexbox in Tailwind is exactly flex.
Step 2: Check other options for validity
Classes like flexbox, flex-container, and flex-layout do not exist in Tailwind.
Final Answer:
flex -> Option A
Quick Check:
Correct class = flex [OK]
Hint: Use exactly flex to enable flexbox [OK]
Common Mistakes:
Adding extra words like 'box' or 'container' to flex