Skip to content

Instantly share code, notes, and snippets.

@phalkunz
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phalkunz/b3259ad89879e542f06b to your computer and use it in GitHub Desktop.
Save phalkunz/b3259ad89879e542f06b to your computer and use it in GitHub Desktop.
Scale embedded video that respects to its apsect ratio using CSS
/**
* Usage:
*
* Set custom (percentage or absolute) width on .video-outer-wrapper
*
* ``html
* <div class="video-outer-wrapper">
* <div class="video-wrapper">
* <iframe ... ></iframe>
* </div>
* </div>
* ``
*
* Resource: https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php
**/
.video-outer-wrapper {
/* Set abosulte width here */
max-width: 100%;
.video-wrapper {
position: relative;
padding-top: 30px;
padding-bottom: ((9 * 100) / 16) * 1%; /* aspect ratio 16:9 */
width: 100%; /* this to be 100% */
height: 0;
iframe {
position: absolute;
top: 0;
left: 0;
width: 100% !important;
height: 100% !important;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment