简体   繁体   English

如何在我的网站上将.webm文件设置为背景?

[英]How can I set a .webm file as a background on my website?

Im looking for a way to set a .webm file as a background on my website, but when I put it on my css the file doesnt show. 我正在寻找一种方法来设置.webm文件作为我的网站上的背景,但当我把它放在我的CSS上时,文件没有显示。

Im trying to set an animated wallpaper on my website, ive been exporting the file on .gif or .mp4, but the file is too large for a website (20mb) so instead I decided to export the file to .webm (named "itry.webm") 我试图在我的网站上设置一个动画壁纸,我一直在.gif或.mp4上导出文件,但文件太大了网站(20mb)所以我决定将文件导出到.webm(名为“itry” .webm“)

So, on my CSS file I got this: 所以,在我的CSS文件中我得到了这个:

position: relative;
    -webkit-box-sizing: border-box; /* Safari<=5 Android<=3 */
    -moz-box-sizing: border-box; /* <=28 */
    box-sizing: border-box;
    background-image: url("img/itry.webm");
    background-position: center; /* Center the image */
    background-repeat: no-repeat; /* Do not repeat the image */
    background-size: cover; /* Resize the background image to cover the entire container */

Instead of displaying the file it displays a white background. 它不显示文件而是显示白色背景。

Sounds like you got a relatively problem. 听起来你有一个相对的问题。

Try: 尝试:

background-image: url("./img/itry.webm");

I recommend using HTML5 video tag however. 不过我推荐使用HTML5视频标签。

<video loop autoplay>
    <source src="video/itry.webm" type="video/webm">
</video>

通过将文件格式更改为.mp4来解决,我认为.webm文件仍然存在与浏览器的兼容性问题,如此处所示浏览器兼容性测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM