I'm using an HTML5 video element as a background layer which works fine, however, it's causing problems with other elements on the page that have a background image with the property background-attachment: fixed
. The background images become unstuck, broken up, or disappear completely. If I change the z-index of the video wrapper div to something positive the problem disappears but that defeats the purpose of using it as a background layer. This problem is only occurring in webkit browsers (Chrome and Safari).
Here's the basic HTML:
<section class="fixed-background">
<p>...</p>
</section>
<section>
<div class="video-background">
<video loop autoplay muted>
<source src="video.mp4" type="video/mp4">
<source src="video.webm" type="video/webm">
</video>
</div>
<p>...</p>
</section>
<section class="fixed-background">
<p>...</p>
</section>
And the CSS:
.fixed-background {
background: url('image.jpg') center center;
background-size: cover;
background-attachment: fixed;
}
.video-background {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
z-index: -1;
}
.video-background video {
min-width: 100%;
min-height: 100%;
}
I've created a sample JSFiddle that illustrates the problem. Works fine in Firefox, but breaks in Chrome/Safari.
Did you find a fix for this? I have the same issue, however only in safari.
Edit This post here fixed it for me.
Chrome position:fixed inside position:absolute breaking with iframe / video
Add this to all position: fixed; elements
-webkit-backface-visibility: hidden;
-webkit-transform: translateZ(0);
Just wrap HTML5 video in dom element with styling rules position: relative; and overflow:hidden; This will fix everything in all browsers!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With