×

css · level 2 · unit 3 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

shares out a grid's free space, a bit like flex-grow.

Fixed columns do not fit every screen. The fr unit means one share of the free space. 1fr 1fr makes two equal columns that stretch with the page, however wide it is.

Mix them: 160px 1fr is a 160px sidebar and a main column that takes the rest. 1fr 2fr gives the second column two shares for every one.

saves typing: repeat(4, 1fr) means 1fr 1fr 1fr 1fr. It is a , a named tool with round brackets after it, that works out a value for you.

<div class="layout">
  <div class="side">Filters</div>
  <div class="main">Search results</div>
</div>
.layout {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 16px;
}
.side {
  background-color: lightgray;
}
.main {
  background-color: aliceblue;
}

Press show my page to see it here.

The sidebar stays 160px on every screen, while the main column stretches and shrinks.