如何仅向特定的div或类提供背景视频。

时间:2016-07-24 07:27:11

标签: javascript css html5 twitter-bootstrap-3

即我想在网站的首页上用一个视频代替滑块或横幅图片。在下面的代码中我想将视频作为背景应用到'视频'课程,我该怎么做才能帮帮我,谢谢。

<body>
    <div class="video">
        <nav>
        </nav>
        <div class="some-text">
            <h1> welcome </h1>
        </div>
    </div>

    <div class="container">

        <!-- here there other content of the site where the video should not appear in background   -->

    </div>

</body>

1 个答案:

答案 0 :(得分:0)

试试这个

var myVideo = document.getElementById("vd");
myVideo.play(); 
.videoBg {
    overflow: hidden;
}

.videoBg video{
    min-width: 100%;
    min-height: 100%;
}

video{
  width:100%;
  height:100%;
}
<body>
    <div class="videoBg">
      <video id="vd">
  <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
Your browser does not support the video tag.
</video> 
    </div>

    <div class="container">
your content
        <!-- here there other content of the site where the video should not appear in background   -->

    </div>

</body>