Codeloft
0 0 XP

Layout with grid

8 min 20 XP + 10 for no hints

Flexbox lines things up in one direction. display: grid places items in rows and columns, which is perfect for galleries and card layouts.

grid-template-columns sets the columns. 1fr 1fr 1fr means three equal columns, each one fr wide, and repeat(3, 1fr) says the same thing more briefly.

gap adds space between rows and columns, just like in flexbox.

Example
<style>
  .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .grid div { background: #c7d2fe; padding: 16px; text-align: center; }
</style>
<div class="grid">
  <div>1</div><div>2</div><div>3</div>
  <div>4</div><div>5</div><div>6</div>
</div>
The grid wraps onto a new row automatically once a row is full.

Your tasks

0 of 3 done
  1. Make .gallery a grid
  2. Give it 3 equal columns
  3. Add a gap between the photos

Quick check

What does grid-template-columns: 1fr 2fr do?

gallery.htmlUpdates as you type