We would like a HTML5 Video to stretch to fit the entire DIV that is to contain it. While keeping Aspect Ratio.
The code is working fine in Chrome and FF but as usual IE is not.
You can see it here:
The video is being stretched using object-fit:cover and IE11 and under don’t support object fit at all. IE Edge (version 16) has partial support but only for images and not videos or other elements.
This fix will work for IE11 but not for IE edge because it understands the object-fit property (even though it doesn’t implement it on videos).
Let all browsers have the auto height and the video will then stretch to 100% and look more or less ok.
.fullwidth-video video{height:auto}
Use a hack for Edge by combining object-fit and a special MS only rule (using the -ms prefix) like this:
.fullwidth-video video{height:auto}
@supports (object-fit: cover){
.fullwidth-video video{height:500px}
}
/* ie edge only gets the following rule */
@supports (object-fit: cover) and (-ms-ime-align:auto) {
.fullwidth-video video{height:auto}
}
The problem with this hack is that when support for Edge arrives then it will still get the old height:auto method (although I don’t see it as a big problem). However hacks are always risky.
Thanks for this suggestion. I am going to work on it.
But not too hot about it.
I guess since less and less people ever use IE, we can just ignore it
But working on it.
Yes Paul, I was referring to the background Video and not the Animated explainer Video.
The Animated explainer Video works fine across all browsers.
It is the background type Video of People which is stretched that does not work right in darn IE
So I applied your hack for IE to display the (background) Video OK. And it does work to the extent that now the (background) Video in IE is stretched to the full dimensions of the DIV containing it. However the Video is cropped top and bottom, so a view point of it is showed. Unlike in FF and Chrome where the whole Video is stretched correctly.
We can live with it as is, since less than 5% of the Site visitors use IE and anyway the Video now covers whole DIV.
I dont consider that a Fix!
I like it how there is “gap at each side of the video holder”. Gives it more easy view point. IMHO. So that is a real design and preference issue.
Yes that is the only fix until object-fit is implemented for videos in Edge. I think it looks better to have the video 100% even if it is enlarged. You could probably move the focal point but it s probably not worth the effort.
You might want to think about that. Are you saying that the height of the video extends taller at wider browser widths so the aspect ratio remains the same in Firefox?
Then let me burst that balloon for you. I see that video behaving in Firefox the way you describe it behaving in IE.
The window for the video has a fixed height of 500px but can extend to the full width of the browser window. When the window extends wider, the video enlarges to fit the width of the window and the top and bottom edges of the video are cropped at the fixed height. When the width of the video window is reduced, at the point where the height of the video matches the fixed height of the window, the video will stop shrinking and the width of the video will be cropped (like background-size:cover)
No I think that’s correct as the only difference between the code I added for IE is that object-fit:cover centers the background video whereas the code I added makes it start at top left. Both examples are the same size as they are stretched to fit the available space whilst maintaining aspect ratio and that means that they both must be the same size except that object-fit centers the result automatically.
I believe we can achieve that result for IE by adding the folloiwng code.
Ron I disregarded the smaller widths as the site is not optimised for smaller screens on desktop anyway as there is a completely different layout triggered when viewed on a device (which we all know is not the desired approach).
However I think the fix is simply to give IE a width auto and the whole thing should still work.
e.g.
.fullwidth-video video{height:auto;width:auto;}
Which I believe means we can lose all the hacks and just do this for all browsers:
That would seem to be a complete representation of the standard object-fit:cover property with the focal point of the image central (the default for object fit).