×

css · level 2 · unit 4 · lesson 1

  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

A adds rules only when the screen is wide enough.

A page looks right on any screen. The main tool is a media query: @media (min-width: 700px) { … }. The rules inside its curly brackets only count when the screen is at least 700px wide.

Write the phone layout first, outside any query. Then add queries that change only what wider screens need. This way of working is called mobile first.

The width where the layout switches is a . Put breakpoints where your design starts to look stretched, not at the size of one particular phone.

<div class="cards">
  <div class="card">Maths</div>
  <div class="card">Art</div>
  <div class="card">Music</div>
  <div class="card">Science</div>
</div>
.cards {
  display: grid;
  gap: 16px;
}
@media (min-width: 700px) {
  .cards {
    grid-template-columns: 1fr 1fr;
  }
}
.card {
  padding: 16px;
  background-color: lightcyan;
}

Press show my page to see it here.

On a phone the cards stack in one column. From 700px wide, they pair up in two.