在Bootstrap中水平居中视频 [英] Horizontally center video in Bootstrap
问题描述
在其他地方进行了研究,无法找到在Bootstrap div / header部分中水平居中视频的解决方案,同时保持视频与顶部垂直对齐。 Div / header部分是100%宽度,在某些视口断点处有两个固定高度。
Researched elsewhere, can't find a solution to horizontally center a video in a Bootstrap div / header section while keeping the video vertically aligned with the top. Div / header section is 100% width with two fixed heights at certain viewport breakpoints.
我尝试删除/重命名< header>
标签,以防Bootstrap的样式发生干扰。尝试< center>
标记,将视频标记指定为 display:inline
以及许多其他尝试。
I've tried removing/renaming the <header>
tag in case Bootstrap's styles interfere. Tried <center>
tags, specifying the video tag as display:inline
and many many other attempts.
此示例中的视频以某些断点为中心,但在其他方面是左对齐的。我希望它在所有视口宽度中居中,并且也在顶部对齐。
The video in this example centers at certain breakpoints but otherwise is left-aligned. I'd like it to be centered throughout all viewport widths, and top aligned as well.
非常感谢!
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;
}
}
推荐答案
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>
</header>
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;
left: 50%;
top: 0;
-ms-transform: translateX(-50%);
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
min-width:100%;
min-height:100%;
z-index: -100;
}
@media (min-width: 768px) {
header {
height: 665px;
}
}
演示链接:https://jsfiddle.net/hellosrini/vwc5hek0/
这篇关于在Bootstrap中水平居中视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!