Sample questions
Question 1Easy
With display: flex and the default flex-direction, along which axis does justify-content align items?
- Both axes
- Neither; it only affects grid
- Horizontally (the main axis)
- Vertically (the cross axis)
Answer: C. Horizontally (the main axis)
Explanation
The default flex-direction is row, so the main axis is horizontal. justify-content works on the main axis and align-items on the cross axis.
Step-by-step solution
- Flex-direction defaults to row, so the main axis runs left to right.
- Justify-content works along the main axis.
- So justify-content aligns items horizontally, which is option C.
Why the other options are wrong
- A. Justify-content does not work on the cross axis, so it does not act on both axes.
- B. Justify-content works in flex layouts; it is not only for grid.
- D. The vertical direction is the cross axis here, and align-items controls it, not justify-content.
Tip: Justify-content is the main axis; align-items is the cross axis.
Question 2Easy
Which property adds space between flex or grid items without adding outer margins?
- gap
- padding
- spacing
- margin-between
Answer: A. gap
Explanation
gap (with row-gap and column-gap) sets the gutters between items in both flex and grid layouts.
Step-by-step solution
- The gap property sets the space between flex or grid items.
- It uses no outer margin, so the edges of the container stay the same.
- So the correct answer is option A, gap.
Why the other options are wrong
- B. Padding adds space inside the container, not between items.
- C. Spacing is not a CSS property.
- D. Margin-between is not a CSS property.
Tip: Use gap for spacing between flex and grid items instead of margins on each item.
Question 3Easy
What layout does grid-template-columns: repeat(3, 1fr) produce?
- Three rows of equal height that share the available space
- Three columns that are each exactly 1 pixel wide
- A single column that is three fractions (3fr) wide
- Three equal-width columns sharing the available space
Answer: D. Three equal-width columns sharing the available space
Explanation
fr is a fraction of the free space. Three 1fr tracks split the width equally.
Step-by-step solution
- repeat(3, 1fr) expands to 1fr 1fr 1fr.
- That makes three columns.
- Each fr takes an equal share of the available space.
Why the other options are wrong
- A. grid-template-columns defines columns, not rows.
- B. fr is a fraction of space, not pixels.
- C. It is three columns, not a single one.
Tip: 3 x 1fr = three equal columns.
Question 4Medium
What does flex: 1 on a flex item mean?
- order: 1
- flex-grow: 1, flex-shrink: 0, flex-basis: auto
- flex-grow: 1, flex-shrink: 1, flex-basis: 0%
- width: 100%
Answer: C. flex-grow: 1, flex-shrink: 1, flex-basis: 0%
Explanation
The shorthand flex: 1 sets grow 1, shrink 1 and a basis of 0%, so items with flex: 1 share the free space equally.
Step-by-step solution
- flex: 1 is shorthand for flex: 1 1 0%.
- That means flex-grow 1, flex-shrink 1, flex-basis 0%.
- Items share free space equally.
Why the other options are wrong
- A. order is a separate property.
- B. That describes flex: auto-like behaviour, with a shrink of 0 and basis auto.
- D. flex: 1 does not set width to 100%.
Tip: Flex 1 means share space equally.
Question 5Medium
In a grid, what does grid-column: 1 / 3 on an item do?
- Spans from line 1 to line 3, covering two columns
- Places the item in the first third of the row
- Places the item in column 3 only
- Spans three columns, from column 1 to column 3
Answer: A. Spans from line 1 to line 3, covering two columns
Explanation
The values are grid line numbers, not column numbers. Lines 1 to 3 enclose columns 1 and 2.
Step-by-step solution
- Grid-column values are grid line numbers, not column numbers.
- Line 1 is the left edge of column 1, and line 3 is the edge after column 2.
- So the item covers columns 1 and 2, spanning two columns, which is option A.
Why the other options are wrong
- B. The values are grid lines, not fractions of a row.
- C. The item covers two columns, not only column 3.
- D. Line 3 is the edge after column 2, so the item spans two columns, not three.
Tip: Grid lines are numbered from 1; a span from line a to line b covers b - a columns.
Question 6Medium
A container has display: flex; flex-direction: column; justify-content: center;. How are its children positioned?
- Centered in both directions
- Centered vertically
- Centered horizontally
- Stretched to fill the width only
Answer: B. Centered vertically
Explanation
With flex-direction: column, the main axis is vertical, so justify-content centers the children vertically.
Step-by-step solution
- Flex-direction: column makes the main axis vertical.
- Justify-content works along the main axis, so it centers the children vertically.
- The horizontal axis is the cross axis and is not centered, so the answer is option B.
Why the other options are wrong
- A. Only the vertical axis is centered, because justify-content acts only on the main axis.
- C. Horizontal centering would need align-items: center in a column layout.
- D. The children are not stretched; justify-content centers them.
Tip: In a column flex container, justify-content works vertically and align-items works horizontally.
Practise all 6 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →