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
Flex Container Layout
📖 Scenario: You are creating a simple webpage section that displays three colored boxes side by side. You want to use CSS Flexbox to arrange these boxes in a row with equal spacing.
🎯 Goal: Build a flex container that arranges three boxes horizontally with space between them.
📋 What You'll Learn
Create a container element in HTML to hold the boxes
Use CSS to make the container a flex container
Arrange the boxes in a row with space between them
Ensure the boxes have visible background colors and fixed size
💡 Why This Matters
🌍 Real World
Flexbox is widely used in web design to create flexible and responsive layouts that adjust to different screen sizes.
💼 Career
Understanding flex containers is essential for front-end developers to build modern, user-friendly websites and applications.
Progress0 / 4 steps
1
Create the HTML structure with three boxes
Write the HTML code to create a <div> with class container that contains three child <div> elements with classes box1, box2, and box3. Each box should have text inside: "Box 1", "Box 2", and "Box 3" respectively.
CSS
Hint
Use a <div> with class container and inside it add three <div> elements with classes box1, box2, and box3. Put the text "Box 1", "Box 2", and "Box 3" inside each box respectively.
2
Add CSS to make the container a flex container
Write CSS to select the class .container and set its display property to flex.
CSS
Hint
Use the CSS selector .container and set display: flex; inside its block.
3
Arrange boxes in a row with space between
Add CSS to the .container to set justify-content to space-between so the boxes spread out evenly in a row.
CSS
Hint
Inside the .container CSS block, add justify-content: space-between; to spread the boxes evenly.
4
Style the boxes with colors and size
Add CSS rules for .box1, .box2, and .box3 to give each a background color (lightcoral, lightseagreen, lightblue respectively), a fixed width of 6rem, a fixed height of 6rem, and center the text horizontally and vertically using flexbox.
CSS
Hint
For each box class, set the background color, width, height, and use flexbox to center the text horizontally and vertically.
Practice
(1/5)
1. What does setting display: flex; on a container do?
easy
A. It hides the container and its children.
B. It makes the container's text bold.
C. It changes the container's background color.
D. It makes the container a flex container, arranging children in a row or column.
Solution
Step 1: Understand the role of display: flex;
Setting display: flex; on a container activates flexbox layout for its children.
Step 2: Effect on child elements
Children inside a flex container are arranged in a row by default or column if specified.
Final Answer:
It makes the container a flex container, arranging children in a row or column. -> Option D
Quick Check:
Flex container = display: flex [OK]
Hint: Remember: display: flex creates a flexible box container [OK]
Common Mistakes:
Confusing flex container with hiding elements
Thinking it changes colors or text styles
Assuming it only affects text formatting
2. Which of the following is the correct CSS syntax to make a container a flex container?
easy
A. container { display: flex; }
B. container { display: block-flex; }
C. container { flex: display; }
D. container { flex-display: true; }
Solution
Step 1: Identify correct CSS property and value
The correct property to enable flexbox is display with the value flex.