Skip to content

Instantly share code, notes, and snippets.

@davestewart
Last active December 25, 2015 04:29
Show Gist options
  • Save davestewart/6917751 to your computer and use it in GitHub Desktop.
Save davestewart/6917751 to your computer and use it in GitHub Desktop.
CSS technique to scale media proportionally, even in responsive sites, no server-side code or JS needed
/* scale video container proportionally to 16:9 */
.video{
width:100%;
padding-bottom: 56.25%;
position: relative;
float: left;
height: 0;
}
/* scale video iframe to 100% */
.video > *{
width:100% !important;
height: 100% !important;
position: absolute;
left: 0;
}
/* clear the floated container */
.video:after{
clear:both;
content:".";
height:0;
font-size:0;
visibility:hidden;
zoom: 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment