WeCodeAcademy

Step 3: A project grid

A portfolio needs to show off work. Wrap the three project article elements in a div.cards and use CSS grid: display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px. Each card gets a background, rounded corners and an accent border on top.

Examplehtml
Open in editor »

repeat(3, 1fr) means three columns that share the space equally. Try repeat(2, 1fr) or add a fourth project to see the grid wrap into a new row.

Your turn: write the code

The grid uses repeat(3, 1fr). Write a function columnsFor(width) that returns 1 when the width is under 640, 2 when it is under 960, and 3 otherwise. Print columnsFor(400), columnsFor(800) and columnsFor(1200).

Quick check

What does grid-template-columns: repeat(3, 1fr) create?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.