Nick Shek's Blog

令你的youtube embed code變為responsive

把youtube的Embed HTML由

<iframe src="//www.youtube.com/embed/AsHKOH03mxw" frameborder="0" height="315" width="560"></iframe>

改成

<div class="video-container">
  <iframe src="//www.youtube.com/embed/AsHKOH03mxw" frameborder="0" height="315" width="560"></iframe>
</div>

之後加入以下CSS

.video-container {
    position: relative;
    padding-bottom: 56.25%;
    padding-top: 30px; height: 0; overflow: hidden;
}

.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}