我希望加载一个视频,就像我在CSS中加载背景图像一样。这背后的原因是我可以自定义视频的更多显示选项,就像我在 CSS 中处理图像一样。我使用视频和源标签加载视频的问题是我无法根据需要更改样式。
有什么建议吗?
试试这个:
.CSS
.video-container {
position: absolute;
top: 0;
bottom: 0;
width: 50%;
height: 100%;
overflow: hidden;
}
.video-container video {
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translate(-50%,-50%);
transform: translate(-50%,-50%);
}
.HTML
<div class="video-container">
<video autoplay muted loop>
<source src="your_video_url.mp4" type="video/mp4">
<source src="your_video_url.webm" type="video/webm">
</video>
</div>
让我知道这是否有效。