Fluid Video Wrapper
A fully fluid video or image wrapper that adapts its size to a fixed aspect ratio controlled by the container's width.
by Dini Mer
HTML
<div class="videoWrapper">
<iframe class="videoElem" type="text/html"
src="//www.youtube.com/embed/YE7VzlLtp-4"
frameborder="0" allowfullscreen>
</iframe>
</div>
CSS
body {
padding: 10%;
}
.videoWrapper {
position: relative;
/* FIXED ASPECT RATIO, EXAMPLE: 16:9 == 56.25% */
padding-top: 56.25%;
height: 0;
}
.videoElem {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
}