Im having trouble overlapping a video element. I have a div that contains a video. even though i have specified that the following div below it should be higher using z-index, and thus appear above the video, it always appears below it. Im not sure what is wrong?
<style>
body{
margin:0;
}
.video-container {
z-index: 0;
width: 100%;
height:600px;
position: relative;
}
.video-container video {
width: 100%;
height: 100%;
position: absolute;
object-fit: cover;
z-index: 1;
}
.video-container .caption {
z-index: 2;
position: relative;
text-align: center;
color: #dc0000;
padding: 10px;
}
#content {
z-index: 3;
background-color:#0F6;
padding:100px;
margin: -100px 20% 100px 20%;
}
</style>
</head>
<body>
<div class="video-container">
<video autoplay muted loop>
<source src="Westgress Video.mp4" type="video/mp4" />
</video>
<div class="caption">
<h2>Your caption here</h2>
</div>
</div>
<div id="content">
<h1>Content for id "content" Goes Here</h1>
<p>djfghkjdf</p>
<p>kdfjhgkjdfdfgbdhfjghkjdfghjkdfhgkj</p>
<p>kjdfbgkjdfghkjdfghkjdfhgkjdfkjg</p>
<p>dfkjbhkjdfg</p>
</div>
</body>
</html>
I thought that using z-index would mean that i could make the #content div appear above the video container. But this does not happen.
3
Answers
You don’t need z-index to do this. You can use a grid stack and as mentioned by CBroe you’ll need to set position relative on the content to enable positioning
Use the below code, use the position style for the content section and manage the content on the video. Currently, I have added a dummy video URL; please replace it with your video.