Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created September 19, 2018 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save productioncoder/06717da101483af458865496dcf28120 to your computer and use it in GitHub Desktop.
Save productioncoder/06717da101483af458865496dcf28120 to your computer and use it in GitHub Desktop.
Youtube Video dynamic resizing with CSS only
/* Rest unchanged */
return (
<div className='video-container'>
<div className="video">
<iframe className='video-player' src={embedUrl} frameBorder='0'
allow='autoplay; encrypted-media' allowFullScreen title='video' />
</div>
</div>
);
.video-container {
position: relative;
width: 100%;
&:before {
content: "";
display: block;
padding-top: 56.25%; // 9 / 16 in percent
}
.video {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
.video-player {
min-height: 480px;
width: 100%;
height: 100%;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment