Bitpath

Lesson 2 · Unit 03

Grid

Rows and columns, tracks, and placing items by line

13 exercisesabout 3 min

What you practise

  • Tracks and the fr unit, repeat and minmax, placing items by line, named areas, grid against flexbox

Try a question from this lesson

Pick one

The rule defines three columns and says nothing about rows. How do the six items arrange themselves?

HTML
<style>
  .g { display: grid;
       grid-template-columns:
         200px 200px 200px; }
</style>
<div class="g">
  <div>1</div><div>2</div><div>3</div>
  <div>4</div><div>5</div><div>6</div>
</div>

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Tracks and fr

A grid is defined by its tracks. This one has three columns.

A fixed track takes its size first. The gaps are taken next. An fr is one share of what is left, so 2fr gets twice as much as 1fr.

CSS
.g {
  display: grid;
  grid-template-columns: 100px 1fr 2fr;
  gap: 20px;
}

Concept

Grid lines

Items are placed between numbered lines, starting at 1. Four columns have five lines.

grid-column: 1 / 3 runs from line 1 to line 3, which covers two columns. span 2 means "two tracks from wherever I start".

Negative numbers count from the far end: 1 / -1 is the full width.

line 1    2    3    4    5
     |    |    |    |    |
     | A  | B  | C  | D  |
     |    |    |    |    |

10 more exercises in the app

  • 5× type the answer
  • 3× multiple choice
  • 1× fill the blanks
  • 1× true or false

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy