In my search for a solution, I have not been able to find a way to horizontally center a video within a Bootstrap div or header section while also keeping the video vertically aligned with the top. The div or header section has a 100% width with fixed heights at specific viewport breakpoints.
Despite my attempts to remove or rename the <header>
tag and using <center>
tags, specifying the video tag as display:inline
, and various other methods, the video in this example only centers at certain breakpoints and is left-aligned otherwise. I would like the video to be centered consistently across all viewport widths and remain top-aligned.
Thank you in advance for any assistance!
HTML:
<header>
<video loop muted autoplay poster="images/3671960.jpg" class="fullscreen-video">
<source src="video/3671960.mp4" type="video/mp4">
</video>
<div class="header-content">
<div class="header-content-inner">
<h1>A bunch of header text.</h1>
</div>
</div>
<div class="launcher">
<div class="launcher-inner">
<a href="#what-i-do" class="btn btn-primary btn-outline-inverse page-scroll text-capitalize">Button text</a>
</div>
</div>
CSS :
header {
position: relative;
text-align: center;
top: 0;
left: 0;
width:100%;
height: 475px;
color: #fff;
overflow: hidden;
margin: 0 auto;
}
header .fullscreen-video {
position: absolute;
top: 0;
left: 0;
min-width:100%;
min-height:100%;
z-index: -100;
}
@media (min-width: 768px) {
header {
height: 665px;
}
}