使用 CSS 向 HTML5 背景视频添加控件
Adding controls to HTML5 background video with CSS
我一直在努力寻找这个问题的答案,我想为 HTML5 背景视频添加控件,以便用户至少可以选择暂停视频以实现可访问性。内置的 HTML5 "Controls" 属性工作得很好,但是一旦我添加 CSS 将视频置于背景中,控件就会消失。如何保留控件并在后台播放视频?
这是我的简单 HTML5 代码:
<div class="fullscreen-bg">
<video controls loop muted autoplay poster="Rustypic.jpg" class="fullscreen-bg-video">
<source src="Rustybeg.webm" srclang="en" type="video/webm">
</video>
</div>
这是我的 CSS 视频:
.fullscreen-bg {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
z-index: -100;
}
.fullscreen-bg__video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
this 之类的怎么样?
.fullscreen-bg {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
z-index: -100;
}
.fullscreen-bg-video {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -5;
}
<div class="fullscreen-bg">
<video controls loop muted autoplay poster="Rustypic.jpg" class="fullscreen-bg-video">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
</div>
<div class="content">NASA is not about the ‘Adventure of Human Space Exploration’…We won’t be doing it just to get out there in space – we’ll be doing it because the things we learn out there will be making life better for a lot of people who won’t be able to go.</div>
请注意 - 除非您出于某种原因希望视频在页面上居中,否则您并不需要 100% 的高度。
我一直在努力寻找这个问题的答案,我想为 HTML5 背景视频添加控件,以便用户至少可以选择暂停视频以实现可访问性。内置的 HTML5 "Controls" 属性工作得很好,但是一旦我添加 CSS 将视频置于背景中,控件就会消失。如何保留控件并在后台播放视频?
这是我的简单 HTML5 代码:
<div class="fullscreen-bg">
<video controls loop muted autoplay poster="Rustypic.jpg" class="fullscreen-bg-video">
<source src="Rustybeg.webm" srclang="en" type="video/webm">
</video>
</div>
这是我的 CSS 视频:
.fullscreen-bg {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
z-index: -100;
}
.fullscreen-bg__video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
this 之类的怎么样?
.fullscreen-bg {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow: hidden;
z-index: -100;
}
.fullscreen-bg-video {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -5;
}
<div class="fullscreen-bg">
<video controls loop muted autoplay poster="Rustypic.jpg" class="fullscreen-bg-video">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
</div>
<div class="content">NASA is not about the ‘Adventure of Human Space Exploration’…We won’t be doing it just to get out there in space – we’ll be doing it because the things we learn out there will be making life better for a lot of people who won’t be able to go.</div>
请注意 - 除非您出于某种原因希望视频在页面上居中,否则您并不需要 100% 的高度。