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
Align Content Using CSS Flexbox
📖 Scenario: You are creating a simple webpage section that displays multiple colored boxes inside a container. You want to control how these boxes are arranged and aligned inside the container using CSS Flexbox.
🎯 Goal: Build a webpage with a container holding six colored boxes. Use CSS Flexbox to align the boxes so they wrap onto multiple lines and the lines are spaced evenly in the container.
📋 What You'll Learn
Create a container with six child boxes
Use CSS Flexbox on the container
Set the container to wrap the boxes onto multiple lines
Use align-content property to space the wrapped lines evenly
Make sure the boxes have visible background colors and fixed size
💡 Why This Matters
🌍 Real World
Aligning multiple items in a container is common in web design for galleries, menus, or product listings where flexible and neat layouts improve user experience.
💼 Career
Understanding CSS Flexbox and align-content is essential for front-end developers to create responsive and visually appealing web pages.
Progress0 / 4 steps
1
Create the HTML structure with container and boxes
Create a <div> with class container. Inside it, create six <div> elements each with class box. Do not add any CSS yet.
CSS
Hint
Use six <div> elements with class box inside the container.
2
Add basic CSS for container and boxes
Add CSS to set the container's width to 20rem and height to 12rem. Set each box's width and height to 4rem. Give each box a background color of lightcoral.
CSS
Hint
Use CSS selectors .container and .box to style the elements.
3
Make the container a flex container and allow wrapping
Add CSS to the .container to make it a flex container by setting display: flex;. Also add flex-wrap: wrap; so the boxes wrap onto multiple lines when needed.
CSS
Hint
Use display: flex; and flex-wrap: wrap; inside .container.
4
Use align-content to space wrapped lines evenly
Add CSS to the .container to set align-content: space-evenly;. This will space the wrapped lines of boxes evenly inside the container's height.
CSS
Hint
Use align-content: space-evenly; inside the .container CSS block.
Practice
(1/5)
1. What does the CSS property align-content control in a flex container?
easy
A. The alignment of individual items along the main axis
B. The background color of the container
C. The font size of the container's text
D. The spacing between rows or columns when items wrap to multiple lines
Solution
Step 1: Understand the role of align-content
This property controls how multiple rows or columns are spaced inside a container when items wrap to more than one line.
Step 2: Differentiate from other properties
align-items aligns individual items on a single line, not spacing between lines. Font size and background color are unrelated.
Final Answer:
The spacing between rows or columns when items wrap to multiple lines -> Option D
Quick Check:
Align-content = spacing between wrapped lines [OK]
Hint: Align-content affects multi-line spacing, not single items [OK]
Common Mistakes:
Confusing align-content with align-items
Thinking it changes font or colors
Using it when items do not wrap
2. Which of the following is the correct syntax to center content along the cross axis in a multi-line flex container?
easy
A. align-content: center;
B. align-items: center;
C. justify-content: center;
D. text-align: center;
Solution
Step 1: Identify the property for multi-line alignment
align-content centers the space between multiple lines in a flex container.
Step 2: Differentiate from other alignment properties
align-items centers items on a single line, justify-content aligns along the main axis, and text-align affects inline text alignment.
Final Answer:
align-content: center; -> Option A
Quick Check:
Center multi-line content with align-content: center [OK]
Hint: Use align-content for multi-line centering, not align-items [OK]
Common Mistakes:
Using align-items instead of align-content
Confusing justify-content with align-content
Applying text-align to flex containers
3. Given this CSS for a flex container with wrapped items: