Responsive Youtube Embed

I saw a few stuff breaking on this site if you view it from an iPhone. The large thumbnail and the youtube embed.

Youtube embeds are iframes with fixed sizes. I thought css cannot fix that since the codes are hardcoded. I was wrong. The solution was quite simple, you need to wrap the iframe with a container and with a little positioning trick, walla.

.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%;
}

 

You can read about the article here.

After adding max-width: 100% on the images, it was a tad broken, turns out you need add some other stuff also.


img {
max-width: 100%;
height: auto;
width: auto; /* Fix for IE */
}

Leave a Reply

"Life is like a camera. Focus only on what is important and you will capture it perfectly."