Common CSS ways to do Aspect Ratio
(on the YouTube Iframe)
-
Padding Hack
.padding-hack {
position: relative;
width: 31vw;
padding-top: 56.25%;
/* calculating 16/9 ratio --- 9 / 16 * 100% = 56.25% */
}
.padding-hack iframe {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
}
-
Viewport width solution
.vw-solution {
width: 31vw;
height: 17.4375vw;
/* calculating 16/9 ratio ---- 31vw / 16 * 9 = 17.4375vw */
}
-
Aspect-ratio new CSS property
.aspect-ratio {
width: 31vw;
aspect-ratio: 16 / 9;
/* aspect-ratio auto calculating 16/9 ratio */
}