I have a section with 2 div. In left div there is one heading and button & in another div there in one video. Now I have a background image for the video, which I tried to add through CSS in the wrapper class, but the dimensions of the background image are giving me trouble. I want to add the video in the middle of the background image. Could you help me this please?
.container {
width: 100%;
margin-top: 20px;
}
.paragrah-desktop {
display: flex;
}
.wrapper {
border: 2px solid black;
background: url(/static/imgs/bg_video.png);
//Dimension is 1920*1080
background-size: contain;
background-repeat: no-repeat;
width: 100%;
height: 0;
}
video {
position: absolute;
width: 80%;
border: 2px solid #7cd959;
}
<section class="container" id="header">
<div class="paragrah-desktop">
<div class="subheader">
<h1 class="desktop-title">UPGRADE ALERTS</b></h1>
<button type="button" class="btn" data-toggle="modal" data-target="#exampleModal">Join
</button>
<p class="header-p">Coming to you July 2023</p>
</div>
<div class="wrapper">
<!-- <video controls>
<source src="{% static 'imgs/mobile_video.webm' %}" type="video/webm">
</video> -->
</div>
</div>
</section>
2
Answers
You don’t have to use position absolute for your video, instead, you could set the display to block and then use margin to center your video like this:
Also if you have to use absolute for the position, here’s how you have to do it:
First you need to give the
position:relative
to the parents which is the.wrapper
andleft: 10%;
to the video:Also once I created this funny app to understand the CSS positioning, I hope you like it:
CSS positioning
Variant with flex:
Screenshot