Home > database >  Background video overlapping button
Background video overlapping button

Time:10-17

So I have a very simple html that makes a video a background video and an audio that plays. Now when I try to add a button, it gets created, but the video overlaps it. How do I fix this? I asked my friend and he said make the buttons z-index higher than the videos in css, but it didnt fix the issue.

#myVideo {
  position: fixed;
  right: 0;
  bottom: 0;
  min-width: 100%;
  min-height: 100%;
  z-index: 0;
}

#myButton {
  width: 300px;
  height: 200px;
  font-size: 18px;
  padding: 10px;
  cursor: pointer;
  z-index: 2;
}
<html lang="en">

<head>
  <link rel="stylesheet" href="/style.css">
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Doffy</title>

  <video autoplay muted loop id="myVideo">
        <source src="/images/doffy.mp4" type="video/mp4">
    </video>
  <button type="button" id="myButton"> New music</button>
  <audio id="BackgroundM" hidden="true">
      <source src=""  type="audio/mp3" id="source">
    </audio>
  <script src="/main.js"></script>
</head>

<body>

</body>

</html>

CodePudding user response:

The z-index property only works on positioned elements, you should add position: relative to your button to make that z-index work.

https://www.w3schools.com/cssref/pr_pos_z-index.asp

  • Related