Last active
February 22, 2016 01:23
-
-
Save stephenbelyea/d7f2d9a6648bcd53acc5 to your computer and use it in GitHub Desktop.
Responsive YouTube Iframe
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
// Add a wrapper to any YouTube video. Depends on jQuery. | |
if ( $('iframe[src*="youtube."]').length ) { | |
$('iframe[src*="youtube."]').each( function () { | |
// Use the video's specified width as a max so we don't stretch. | |
var width = $(this).attr('width'); | |
$(this).wrap('<div class="video-wrap" style="max-width:'+width+'px;"><div class="inner"></div></div>'); | |
}); | |
} |
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
// Style the wrapper | |
.video-wrap { | |
display: block; | |
margin: 5px auto 25px; | |
.inner { | |
position: relative; | |
padding-bottom: 56.25%; | |
padding-top: 10px; | |
width: 100%; | |
height: 0; | |
overflow: hidden; | |
} | |
iframe { | |
position: absolute; | |
top:0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment