Challenge - 5 Problems
Grid Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ layout
intermediateWhat is the number of columns in this grid container?
Consider the following CSS code for a grid container. How many columns will the grid have?
CSS
display: grid; grid-template-columns: repeat(3, 1fr);
Attempts:
2 left
💡 Hint
The repeat function sets how many columns are created.
✗ Incorrect
The property grid-template-columns: repeat(3, 1fr) creates 3 equal columns in the grid container.
❓ selector
intermediateWhich CSS property makes an element a grid container?
You want to turn a
into a grid container. Which CSS property and value should you use?
Attempts:
2 left
💡 Hint
The display property controls the layout type of an element.
✗ Incorrect
Setting display: grid; makes the element a grid container, enabling grid layout for its children.
❓ rendering
advancedWhat will be the width of each column in this grid container?
Given this CSS, what is the width of each column if the container is 600px wide?
CSS
display: grid; grid-template-columns: 100px 2fr 1fr;
Attempts:
2 left
💡 Hint
fr units divide remaining space proportionally after fixed widths.
✗ Incorrect
The first column is fixed 100px. Remaining space is 500px (600-100). 2fr + 1fr = 3fr total. So 2fr = 2/3 * 500 = 333.33px, 1fr = 1/3 * 500 = 166.67px.
❓ accessibility
advancedWhich practice improves accessibility for grid containers?
When using CSS grid for layout, which practice helps screen reader users understand the page structure better?
Attempts:
2 left
💡 Hint
Screen readers rely on meaningful HTML tags.
✗ Incorrect
Using semantic elements like , , inside grid containers helps screen readers understand content roles and structure.
🧠 Conceptual
expertWhat happens if you set grid-template-columns: auto auto auto; on a grid container with three items of different content widths?
Consider a grid container with three items. The CSS is:
grid-template-columns: auto auto auto;
What will be the width of each column?
Attempts:
2 left
💡 Hint
The auto keyword sizes columns based on content.
✗ Incorrect
Using auto for columns means each column's width fits its widest content, so columns can have different widths.
Practice
1. What CSS property do you use to make an element a grid container?
easy
Solution
Step 1: Understand grid container basics
To create a grid layout, the container must havedisplay: grid;set.Step 2: Check other options
display: flex;creates a flexbox, not grid.position: grid;is invalid.grid-template-columnsdefines columns but does not make container a grid.Final Answer:
display: grid; -> Option DQuick Check:
Grid container = display: grid; [OK]
Hint: Grid container always needs display: grid; [OK]
Common Mistakes:
- Using display: flex; instead of grid
- Trying to use position: grid;
- Setting grid-template-columns without display: grid;
2. Which of the following is the correct syntax to create a grid with 3 equal columns?
easy
Solution
Step 1: Understand grid-template-columns syntax
The propertygrid-template-columnsdefines columns. Using1fr 1fr 1frcreates 3 equal columns.Step 2: Check other options
3pxis a fixed small width, not equal columns.grid-columnsis invalid property.grid-template-rowssets rows, not columns.Final Answer:
grid-template-columns: 1fr 1fr 1fr; -> Option AQuick Check:
Equal columns = grid-template-columns: 1fr 1fr 1fr; [OK]
Hint: Use grid-template-columns with 1fr units for equal columns [OK]
Common Mistakes:
- Using grid-columns instead of grid-template-columns
- Confusing rows and columns properties
- Using fixed px values for equal flexible columns
3. Given this CSS:
.container {
display: grid;
grid-template-columns: 100px 200px;
grid-template-rows: 50px 50px;
}
How many grid cells are created inside .container?medium
Solution
Step 1: Calculate columns and rows
There are 2 columns (100px and 200px) and 2 rows (50px and 50px).Step 2: Multiply columns by rows
Total grid cells = 2 columns x 2 rows = 4 cells.Final Answer:
4 -> Option AQuick Check:
2 columns x 2 rows = 4 cells [OK]
Hint: Multiply number of columns by rows for total grid cells [OK]
Common Mistakes:
- Adding columns and rows instead of multiplying
- Counting only columns or only rows
- Confusing grid cells with grid lines
4. What is wrong with this CSS if the goal is to create a grid container with 3 equal columns?
.grid {
display: grid;
grid-template-columns: repeat(3);
}medium
Solution
Step 1: Check repeat() syntax
Therepeat()function needs two arguments: number of times and size, e.g.repeat(3, 1fr).Step 2: Identify the error
Here, onlyrepeat(3)is given, missing the size argument, so it's invalid.Final Answer:
repeat() requires two arguments: count and size -> Option CQuick Check:
repeat() needs count and size [OK]
Hint: repeat() always needs count and size, like repeat(3, 1fr) [OK]
Common Mistakes:
- Using repeat() with only one argument
- Forgetting to specify display: grid;
- Thinking repeat() is invalid in grid-template-columns
5. You want a grid container that has 2 columns: the first column is 150px wide, and the second column fills the remaining space. Which CSS is correct?
hard
Solution
Step 1: Understand fixed and flexible columns
150px is fixed width. To fill remaining space, use1frwhich means flexible fraction.Step 2: Check options
display: grid; grid-template-columns: 150px auto; usesautowhich sizes based on content, not remaining space. Options B and D put 150px in wrong column order.Final Answer:
display: grid; grid-template-columns: 150px 1fr; -> Option BQuick Check:
Fixed + flexible = 150px 1fr [OK]
Hint: Use 1fr for flexible space after fixed width [OK]
Common Mistakes:
- Using auto instead of 1fr for flexible space
- Swapping column order
- Not setting display: grid;
