Video like Background HTML 5 doesn’t work on Safari and Chrome on Mac

Asked

Viewed 675 times

1

I put a video as background of a site with HTML 5, I open in Chrome and Firefox on Windows and the video rolls normal, but when I open on Mac (Chrome version 67.0.3396.40, and Safari 11.1) the video does not roll... Does anyone know any solution?

HTML:

<div class="wrap">
                <div class="bg-video">
                    <video autoplay loop src="images/video-serv.mp4"></video>
                </div>
</div>

CSS:

.wrap {
    /*Ajuste a largura e altura desejadas aqui*/
    width: 100%;
    height: 100%;

    /*isto fará o elemento video e o .container se adaptarem ao .wrap*/
    position: relative;
}
.wrap > .bg-video {
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1; /*apenas um -1 é necessário quando se trabalha com relative + absolute, sendo pai e filho*/
    width: 100%;
    height: 100%;
    overflow: hidden; /* evita do video passar a altura desejada do .wrap */
}
.wrap > .bg-video > video {
    width: 100%;
}

1 answer

1


Thayna I don’t have a Mac here to test, but its tag video can be built with the source within the tag video, which is more suitable. It might work like this on Mac..., but as I said here I have no way to test Ness platform.

Another detail, swap test by changing position:Absolute for relative, in this class .wrap > .bg-video { position: relative; ....}

.wrap {
    /*Ajuste a largura e altura desejadas aqui*/
    width: 100%;
    height: 100%;

    /*isto fará o elemento video e o .container se adaptarem ao .wrap*/
    position: relative;
}
.wrap > .bg-video {
    position: relative;
    top: 0;
    left: 0;
    z-index: -1; /*apenas um -1 é necessário quando se trabalha com relative + absolute, sendo pai e filho*/
    width: 100%;
    height: 100%;
    overflow: hidden; /* evita do video passar a altura desejada do .wrap */
}
.wrap > .bg-video > video {
    width: 100%;
}
<div class="wrap">
    <div class="bg-video">
        <video autoplay loop>
            <source src="https://www.w3schools.com/tags/movie.mp4" type="video/mp4"  />
        </video>
    </div>
</div>

Here are some examples of tag usage video, vc can even test on Mac https://www.w3schools.com/tags/tag_video.asp

  • Hi Hugo, I put the source inside the video tag and it worked on safari and firefox on Mac, but Chrome is not working yet...

  • Are you even listening to the sound in Chrome, or not even that? If the sound is appearing very likely your video is there, but it is hidden outside the visible area or behind another element...

  • 1

    The video I’m using has no sound... I’m going to do a test with some video with sound.

  • The video with sound did not work either and can not hear the sound in Chrome... It is very strange in other browsers worked normal and in Windows Chrome too.

  • Ollie, I got it fixed! i left HTML only with the video tag like this: <video autoplay muted loop id="myVideo"> <source src="images/video-Serv.mp4" type="video/mp4"> </video> CSS like this: #Xa;#myVideo { position: Fixed; right: 0; bottom: 0; min-width: 100%; min-height: 100%; } And it worked... I think my previous css was influencing something... Thanks for the help :)

  • @Because it is I was suspicious that it would be the CSS, the problem is that I do not have a Mac on hand to do these rss tests, but how nice that solved! Only one thing, if you used position:fixed be sure to test on iPhone, because until a while ago this type of position didn’t used to work well in Safari, dps do the test there if your page needs to be mobile tb

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.