Skip to content

Instantly share code, notes, and snippets.

@shanewholloway
Created June 15, 2022 19:06
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 shanewholloway/a35f176ea7dce3cfed1b9d0d21c9afc1 to your computer and use it in GitHub Desktop.
Save shanewholloway/a35f176ea7dce3cfed1b9d0d21c9afc1 to your computer and use it in GitHub Desktop.
aspect-ratio center box CSS
/* from Kevin Powell's [3 useful CSS tricks](https://www.youtube.com/watch?v=HOM47v73yG8)
* for <div class=box></div>
* useful for iframes, videos, pictures, etc.
*/
.box {
width: 25rem;
aspect-ratio: 1 / 1;
position: fixed;
inset: 0rem; /* sets top/bottom/left/right to same value */
margin: auto; /* center in available space -- uses inset, width, and aspect-ratio to work */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment