I'm using the technique described here to make an iframe (video) responsive. Essentially the iframe is absolutely positioned within a wrapper element with a 100% width. The wrapper element has it's padding set based on the aspect ratio of the video:
.embed-responsive {
position: relative;
/* video height / video width */
padding-bottom: 56.2%;
height: 0;
overflow: hidden;
}
.embed-responsive iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
I need to be able to center the iframe vertically in the parent container (which has a 100% height).
I've achieved this before using this technique but it only works on inline-block
elements. If I change .embed-responsive
to inline-block
it breaks.
So is there an alternative (preferably CSS only) technique I can use to vertically center the iframe, whilst still being responsive? This must work as the browser is resized.
http://jsfiddle.net/benfosterdev/xfA3L/