Skip to content

Instantly share code, notes, and snippets.

@chekle
Created June 29, 2023 23:14
Show Gist options
  • Save chekle/c73a4d8de7b5e447001e7dfc643efaa0 to your computer and use it in GitHub Desktop.
Save chekle/c73a4d8de7b5e447001e7dfc643efaa0 to your computer and use it in GitHub Desktop.
Background Image Sizing using aspect ratio
aspect-ratio: 16 / 9;
.image{
aspect-ratio: 16 / 11;
background-repeat: no-repeat;
background-size:contain;
background-position:center;
}
This essentially makes a background image work proportionally across responsive/different screen sizes without having to set the height at each different breakpoint.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment