Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
Created September 30, 2021 19:45
Show Gist options
  • Save everaldomatias/61874dc2341ef89bc14391f78d5f3018 to your computer and use it in GitHub Desktop.
Save everaldomatias/61874dc2341ef89bc14391f78d5f3018 to your computer and use it in GitHub Desktop.
Make div with aspect-ratio 16:9 and centered image
.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