Closed
Description
There is a new property coming out that is aspect-ratio
which easily accomplishes this. https://web.dev/aspect-ratio/
I believe you can do this with a fallback for the majority of browsers.
div {
background: lightblue;
width: 100%;
// New aspect-ratio property
aspect-ratio: 16 / 9;
}
// Fallback (current, using padding hack)
@supports not (aspect-ratio: 16 / 9) {
div::before {
float: left;
padding-top: 56.25%;
content: '';
}
div::after {
display: block;
content: '';
clear: both;
}
}
Metadata
Metadata
Assignees
Labels
No labels