986 B
986 B
title, tags, expertise, cover, firstSeen, lastUpdated
| title | tags | expertise | cover | firstSeen | lastUpdated |
|---|---|---|---|---|---|
| Fit image in container | layout,visual | intermediate | blog_images/succulent-3.jpg | 2018-10-31T08:34:49+02:00 | 2020-12-30T15:37:37+02:00 |
Fits an positions an image appropriately inside its container while preserving its aspect ratio.
- Use
object-fit: containto fit the entire image within the container while preserving its aspect ratio. - Use
object-fit: coverto fill the container with the image while preserving its aspect ratio. - Use
object-position: centerto position the image at the center of the container.
<img class="image image-contain" src="https://picsum.photos/600/200" />
<img class="image image-cover" src="https://picsum.photos/600/200" />
.image {
background: #34495e;
border: 1px solid #34495e;
width: 200px;
height: 200px;
}
.image-contain {
object-fit: contain;
object-position: center;
}
.image-cover {
object-fit: cover;
object-position: right top;
}