Created
September 30, 2021 19:45
-
-
Save everaldomatias/61874dc2341ef89bc14391f78d5f3018 to your computer and use it in GitHub Desktop.
Make div with aspect-ratio 16:9 and centered image
This file contains hidden or 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
.ratio { | |
// aspect-ratio: 16 / 9; | |
overflow: hidden; | |
position: relative; | |
&::before { | |
content: ""; | |
padding-top: 56.25%; | |
float: left; | |
} | |
&::after { | |
clear: left; | |
content: " "; | |
display: table; | |
} | |
img { | |
max-width: 100%; | |
height: auto; | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
transform: translate(-50%, -50%); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment