Menu

The Mathematics of Aspect Ratios: How Euclidean GCD and Modern CSS Eliminated the 56.25% Hack
πŸ“°

The Mathematics of Aspect Ratios: How Euclidean GCD and Modern CSS Eliminated the 56.25% Hack

DEV Community: cssΒ·Urban MixoΒ·7 days ago
#ssb0mFh0
#devtocss#devto#dev#height#ratio
Reading 0:00
15s threshold

The Mathematics of Aspect Ratios: How Euclidean GCD and Modern CSS Eliminated the 56.25% Hack

If you worked in frontend web development prior to 2021, you almost certainly wroteβ€”or copy-pastedβ€”this grotesque snippet of CSS into a production stylesheet:

/* THE LEGACY PADDING-BOTTOM HACK */ .video-container { position : relative ; width : 100% ; height : 0 ; padding-bottom : 56.25% ; /* 9 divided by 16 = 0.5625 */ }

.video-container iframe , .video-container video { position : absolute ; top : 0 ; left : 0 ; width : 100% ; height : 100% ; }

Enter fullscreen mode

Exit fullscreen mode

For more than a decade, this was the industry-standard technique for making an embedded YouTube video or canvas element maintain a 16:9 widescreen ratio without collapsing into zero height.

Because the CSS specification historically calculated percentage padding relative to the width of the containing block, frontend engineers exploited this quirk by setting height: 0 and driving vertical layout space purely through bottom…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.