Last active
September 28, 2020 13:03
-
-
Save yoksel/2415b89242095c517c679b41e40f658a to your computer and use it in GitHub Desktop.
CSS for adaptive video
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
.video { | |
/* Get aspect ratio */ | |
--aspect-ratio: calc(var(--height) / var(--width)); | |
/* Add units to height */ | |
--height-with-units: calc(var(--height) * 1px); | |
max-width: 100%; | |
/* Get minimal of initial height | |
or height calculated from window width */ | |
height: min(calc(100vw * var(--aspect-ratio)), var(--height-with-units)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment