After implementing the solution from this helpful answer, I have successfully used video[poster]{object-fit:fill}
in my css to prevent distorted poster images in html5 videos. Now, I am looking to use CSS to display different posters for a video based on screen size (mobile or desktop). However, trying
video[poster]{background-image:url(poster.jpg)
did not yield any results, indicating that poster
may not be a background property. To address this issue, I attempted to modify javascript code found here:
function myFunction(x) {
if (x.matches) { // If media query matches
document.getElementById("video").poster = "poster1.jpg";
} else {
document.getElementById("video").poster = "poster2.jpg";
}
}
var x = window.matchMedia("(max-width: 700px)")
myFunction(x) // Call listener function at run time
x.addListener(myFunction)
Unfortunately, this approach did not work as expected. It is possible that there is a small detail missing (even the original failed javascript validation). Does anyone know how to effectively apply media queries to the poster property?