×

css · level 2 · unit 7 · lesson 4

  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 responsive card layout is many small rules working together.

A card is a : a reusable piece of a page, styled the same wherever it appears. Build one card first, then the layout that holds many of them.

Lay the cards out with a grid, one column on phones. Add a media query or auto-fit for more columns on wide screens. Then give photos object-fit, badges absolute and buttons a transition.

Check every piece on a narrow screen and a wide one. Most layout bugs only show up at one size.

<div class="cards">
  <div class="card">Lemon cake</div>
  <div class="card">Garden salad</div>
  <div class="card">Meatballs</div>
</div>
.cards {
  display: grid;
  gap: 16px;
}
@media (min-width: 600px) {
  .cards {
    grid-template-columns: 1fr 1fr;
  }
}
.card {
  position: relative;
  padding: 16px;
  background-color: snow;
}

Press show my page to see it here.

position: relative gets each card ready to hold a badge of its own.