简体   繁体   English

将HTML5视频元素覆盖在另一个视频元素上。

[英]Overlaying an HTML5 video element over another video element.

I am trying to overlay 2 video elements, where one lies directly on top of another. 我试图覆盖2个视频元素,其中一个直接位于另一个之上。 Obviously, the one on top will be smaller than the other such that both are visible. 显然,顶部的那个将比另一个小,使得两者都可见。 So far, the only things I have been able to find are overlaying text over the video, but most of the time the examples I have seen used hardcoded distances from the top of the page to accomplish this. 到目前为止,我能够找到的唯一内容是在视频上覆盖文本,但大多数时候我看过的例子都使用了从页面顶部开始的硬编码距离来实现这一目标。

Here's what I have tried: 这是我尝试过的:

HTML: HTML:

<div class='video-container'>
   <video class='userVideo' id="localVideo" autoplay></video>
   <video class='peerVideo' id='peerVideo' autoplay></video>
</div>

CSS: CSS:

.userVideo {
    height: 200px;
    width: 200px;
    float: left;
    border:5px solid orange;
    position: absolute; 
    top: 100px; 
}

.peerVideo {
    height: 200px;
    width: 200px;
    border:5px solid blue;
}

So far, the only thing I have been able to achieve is a text div overlapping a single video. 到目前为止,我唯一能够实现的是一个重叠单个视频的文本div。 Is there a way to overlap 2 videos or even nest a video within another? 有没有办法重叠2个视频甚至将视频嵌入另一个视频?

What you need to do is set .video-container to position: relative; 你需要做的是将.video-container设置为position: relative; , and then make the two videos position: absolute; ,然后使两个视频的position: absolute; this will simply overlay your videos on top of each other and encapsulate them in .video-container 这将简单地将您的视频叠加在一起, .video-container它们封装在.video-container

here's a fiddle with the changes to your css 这里是你的css变化的小提琴

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

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