Created
June 15, 2022 19:06
-
-
Save shanewholloway/a35f176ea7dce3cfed1b9d0d21c9afc1 to your computer and use it in GitHub Desktop.
aspect-ratio center box CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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