View on GitHub

Notes

reference notes

Responsive Images

The Basics

Background-size, Background-position, and Object-fit

Demo

Background-size and Background-position

Here’s a demo you can play with:

<!-- HTML -->
<div class="background-image-demo"></div>
/* CSS */
.background-image-demo {
  background-image: url('your-image-url.jpg');
  background-size: cover;
  background-position: center;
  width: 300px;
  height: 200px;
}

Object-fit

Here’s a demo of object-fit on an image:

<!-- HTML -->
<img src="your-image-url.jpg" class="object-fit-demo" alt="Demo Image">
/* CSS */
.object-fit-demo {
  width: 300px;
  height: 200px;
  object-fit: cover;
}

Even More Control