Created
September 9, 2015 05:58
-
-
Save jamenlyndon/306b029db8e003e16034 to your computer and use it in GitHub Desktop.
Resize at aspect ratio with pure CSS
This file contains 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
<div class='container'> | |
<iframe src='video.mp4' frameborder='0'></iframe> | |
</div> | |
<style type='text/css'> | |
.container { | |
position: relative; | |
width: 100%; | |
padding-bottom: 56.25%; // This variable defines the height to width ratio | |
} | |
.container iframe { | |
position: absolute; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
} | |
/* COMMON ASPECT RATIOS | |
--------------|---------------------- | |
aspect ratio | padding-bottom value | |
--------------|---------------------- | |
16:9 | 56.25% | |
4:3 | 75% | |
3:2 | 66.66% | |
8:5 | 62.5% | |
*/ | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment