0

The code works well on Desktop but when I go and try to see this on my phone it won't automatically play. Is there a way to make it play on mobile too? Is there any kind of attribute or maybe even some javascript i could use to force it play when the DOM is loaded?

<style>
.video-background {
      position: relative;
      width: 100%;
      height: 100vh;
      overflow: hidden;
    }

    .video-background video {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      z-index: -1;
    }

    .overlay {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, 0.5);
      z-index: -1;
    }

    .caption-container {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      text-align: center;
      color: white;
      z-index: 1;
    }
</style>

This is my css and my html.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Video Background Example</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
  <div class="video-background">
    <video autoplay muted loop>
      <source src="https://theadvocatestg.wpengine.com/wp-content/uploads/2023/07/Drone-Horizontal.mp4" type="video/mp4">
      Your browser does not support the video tag.
    </video>
    <div class="overlay"></div>
  </div>

  <div class="caption-container">
    <h1>Welcome to Our Website</h1>
    <p>This is a sample caption placed on top of the video background.</p>
  </div>

  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

https://codepen.io/fjadvocates/pen/eYQqrwa

Kaiido
  • 123,334
  • 13
  • 219
  • 285
fjimenez
  • 59
  • 7

0 Answers0