在CSS中,我们可以使用background属性将背景设置为图像,原色或渐变。但是,有时我们可能希望将视频作为背景。在这篇文章中,我们将学习如何将视频插入CSS背景中。首先,我们需要在HTML文档中添
<div id="video-container"></div>
#video-container { position: fixed; z-index: -1; width: 100%; height: 100%; overflow: hidden; } #video-container video { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); min-width: 100%; min-height: 100%; }
<video autoplay muted loop> <source src="video.mp4" type="video/mp4"> </video>
<div id="video-container"> <video autoplay muted loop> <source src="video.mp4" type="video/mp4"> </video> </div> #video-container { position: fixed; z-index: -1; width: 100%; height: 100%; overflow: hidden; } #video-container video { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); min-width: 100%; min-height: 100%; }
粉丝
0
关注
0
收藏
0