html - 如何在网站 HTML/CSS 上放置背景视频循环

标签 html css video

我想在我的网站上放置一个视频作为背景视频。我研究了很多,但它不起作用,我也不知道为什么。

在我的 html 上我有:

<video id="bgVideo" controls preload="true" autoplay loop muted>
    <source src="../images/Home_Page.mp4" type="video/mp4" >
    <source src="../images/Home_Page.ogv" type="video/ogg" >    
    <source src="../images/Home_Page.webm" type="video/webm" > 
</video>     
<script src="scripts/html5ext.js" type="text/javascript"></script> 

在我的 CSS 上我有:

body
{
background:  url("../images/Home_Page.png") no-repeat fixed center;
}

video#bgVideo {
position: fixed;
right: 0;
bottom: 0;
width: auto;
min-width: 100%;
height: auto;
min-height: 100%;
z-index: -100;    
background-size: cover;
}

但是,视频没有播放并且背景保持白色。有什么解决这个问题的建议吗??

非常感谢

最佳答案

这应该可行

   <video id="bgVideo" controls preload="true" autoplay loop muted>
      <source src="Home_Page.mp4" type="video/mp4" /> 
       <source src="Home_Page.ogv" type="video/ogv" />    
      <source src="Home_Page.webm" type="video/webm" /> 
      
   </video>

此外,您应该创建一个 htaccess 文件/修改您的 htaccess 文件以包含以下内容

   AddType video/mp4 .mp4 .m4v
   AddType video/ogg .ogv
   AddType video/webm .webm

执行此操作的有用教程是 here

关于html - 如何在网站 HTML/CSS 上放置背景视频循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24293102/

相关文章:

javascript - 圆形对象内的图像导致像素化 d3 js

html - 在添加了图形覆盖的网站上直播直播

用于基于视频的应用程序的 Java : Good choice?

javascript - 如何取消静音背景视频

html - 如何获取屏幕宽度并在CSS中为其添加一些值

javascript - 在 jQuery/CSS 中使用上下文工具提示弹出叠加层

css - Div 布局 : static left column width , strchacle 右列宽度

javascript - jquery Accordion 式页面选项卡导航

php - 通过 php 和 mysql 隐藏真实视频/文件 URL 并使用查询

html - 如何使用 Javascript 转换 html 中的重音字符?