Skip to content

Instantly share code, notes, and snippets.

@bekapod
Last active December 15, 2015 07:29
Show Gist options
  • Save bekapod/5224211 to your computer and use it in GitHub Desktop.
Save bekapod/5224211 to your computer and use it in GitHub Desktop.
CSS: Responsive Video
>> Wrapping the iframe in another element will give us the control we need to add proper responsive functionality to the video.
.video {
position: relative;
padding-bottom: 56.25%;
height: 0;
overflow: hidden;
}
.video iframe,
.video object,
.video embed {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
>> Setting the .video wrapper’s padding-bottom: 56.25%; is the magic in this method. Using padding means the percentage used will be based on the parent’s width; ‘56.25%’ will create a 16:9 aspect ratio. Do the maths yourself, if you want. 9 / 16 = 0.5625. 0.5625 * 100 = 56.25 (this is our per cent).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment