Skip to content

Instantly share code, notes, and snippets.

@saltnpixels
Created June 17, 2021 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saltnpixels/58003746bb2041972106c767917f4e97 to your computer and use it in GitHub Desktop.
Save saltnpixels/58003746bb2041972106c767917f4e97 to your computer and use it in GitHub Desktop.
aspect-ratio images
.aspect-ratio {
position: relative;
// needs a set height, so override when using on a component
&::before {
content: "";
display: block;
height: 0;
width: 100%;
}
& img {
height: 100%;
left: 0;
object-fit: cover;
object-position: center;
position: absolute;
top: 0;
width: 100%;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment