by Flo Preynat

More of a reminder than a pure detailed blogpost, this code snippet will be my go-to resource when I embed videos in a project, and obviously want them to be responsive and well behaved whatever the size of the terminal.

You all know that setting the video object to width:100% won’t be enough to make it look good since the height/width ratio won’t be respected.

Seen this at btconf, during Ethan Marcotte‘s talk, and thought I would use this pure (+ simple + clever) css technique. As I looked for it again on the web, I found it hard to locate it so the reason of this blogpost.

.video-container {
    position: relative;
    height: 0;
    padding-bottom: 56.25%;
}

.video-container > * {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 100%;
}

There’s a codepen for it.

So long.

My name is Flo Preynat and I am the freelance webdesigner and developer behind shoogle designs. I live in France and specialize in responsive web design. Give me a shoogle or get in touch with me on twitter.

Follow @shoogledesigns

Most Recent Posts

Special Recent Posts

Sip: a color picker refreshingly simple indeed

Sip: a color picker refreshingly simple indeed

July 10th, 2014

I've just discovered Sip, a color picker app for Mac users. "Just discovered" since it's been around[...]

Perch – the CMS that does not pollute your web design workflow

Perch - the CMS that does not pollute your web design workflow

July 7th, 2014

I have recently finished a project based on Perch, the clever 'little' CMS created by edgeofmyseat.c[...]

Project Naphta: a nifty extension to play with text embedded in images

Project Naphta: a nifty extension to play with text embedded in images

June 9th, 2014

We've all been there. You want to select a good chunk of text on a website, only to realise you can'[...]

Free photos for your web design projects

Free photos for your web design projects

June 4th, 2014

Nothing beats using a real professional photographer when working on a cool project. You can be the[...]

Beyond Tellerand 2014 : a look back

Beyond Tellerand 2014 : a look back

May 21st, 2014

I'm just back from Düsseldorf, having attended for the first time Beyond Tellerand, the now-famous w[...]

Comments

Be the first to drop your two cents here!