【发布时间】:2016-09-05 13:36:37
【问题描述】:
我有以下标记:
.jumbotron {
position: relative;
z-index: -101;
overflow: hidden;
height: 500px;
background: red;
}
.jumbotron video {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
z-index: -100;
}
.video-content {
text-align: center;
color: #fff;
}
<div class='jumbotron'>
<video autoplay loop class="fillWidth">
<source src="https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4" type="video/mp4" />
<source src="video.ogv" type="video/ogv" />
<source src="video.webm" type="video/webm" />Your browser does not support the video tag. I suggest you upgrade your browser.
</video>
<div class='video-content'>
<h1>Welcome to the Site</h1>
<p>This is just a test but it shows a background video</p>
</div>
</div>
<div class='container-fluid'>
<div class='row'>
<div class='col-md-12'>
<h2>Section Heading</h2>
</div>
</div>
</div>
我的问题是关于video 背景的响应能力。当我将视口缩小时,video 最终开始缩小,而父 div 仍然比它长 - 导致不需要的红色背景。
如何确保父 div 随视频大小缩放?所以当我把它直接带到> 480px 时,h2 标签就会在视频的正下方。
你可以看到一个小提琴here
【问题讨论】:
标签: html css video responsive-design html5-video