×

css · level 2 · unit 7 · lesson 3

  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

fills a frame without squashing the picture.

Give a picture a width and height that do not match its shape and it stretches, like a face in a funfair mirror. object-fit fixes that.

fills the whole box and trims the edges that do not fit. shows the whole picture and leaves empty space instead. The default, fill, stretches.

For card photos, width: 100% plus a fixed height and object-fit: cover gives every card the same neat frame, whatever shape its photo is.

<div class="card">
  <img class="thumb" src="dog.svg" alt="Rex the dog">
  <h3>Rex</h3>
</div>
.card {
  width: 220px;
}
.thumb {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 8px;
}

Press show my page to see it here.

Change cover to fill and watch Rex stretch out of shape.