Does anyone know how to resize the HTML5 video poster such that it fits the exact dimensions of the video itself?
here's a jsfiddle which shows the problem: http://jsfiddle.net/zPacg/7/
here's that code:
HTML:
<video controls width="100%" height="100%" poster="http://www.wpclipart.com/blanks/buttons/glossy_buttons/glossy_button_blank_orange_rectangle.png">
<source src="http://demo.inwebson.com/html5-video/iceage4.mp4" type="video/mp4" />
<source src="http://demo.inwebson.com/html5-video/iceage4.ogg" type="video/ogg" />
<source src="http://demo.inwebson.com/html5-video/iceage4.webm" type="video/webm" />
</video>
CSS:
video{
border:1px solid red;
}
Notice that the orange rectangle doesn't scale to the red border of the video.
Also, just adding the CSS below doesn't work either as it rescales the video along with the poster:
video[poster]{
height:100%;
width:100%;
}
You can use a transparent poster image in combination with a CSS background image to achieve this (example); however, to have a background stretched to the height and the width of a video, you'll have to use an absolutely positioned
<img>
tag (example).It is also possible to set
background-size
to100% 100%
in browsers that supportbackground-size
(example).I was playing around with this and tried all solutions, eventually the solution I went with was a suggestion from Google Chrome's Inspector. If you add this to your CSS it worked for me:
You can use poster to show image instead of video on mobile device(or devices which doesn't support the video autoplay functionality). Because mobile devices not support video autoplay functionality.
Now you can just style the poster attribute which is inside the video tag for mobile device via media-query.
Depending on what browsers you're targeting, you could go for the object-fit property to solve this:
or maybe
fill
is what you're looking for. Still under consideration for IE.