Html 在 HTML5 视频上方添加文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10422105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:06:12  来源:igfitidea点击:

Add text above HTML5 Video

htmlcsshtml5-video

提问by jalf

Need Help on adding text on top of, so the text is overlaying an HTML 5 Video, And I also need to add a form inputs and buttons as well below is my HTML5 Video Code.

在顶部添加文本需要帮助,因此文本覆盖了 HTML 5 视频,而且我还需要添加表单输入和按钮,下面是我的 HTML5 视频代码。

<video id="video" width="770" height="882" onclick="play();">
<source src="video/Motion.mp4" type="video/mp4" />
</video>

回答by Matthew Darnell

Surely you are looking for more than this:

当然,您正在寻找的不止这些:

<div class="container">
    <video id="video" width="770" height="882" onclick="play();">
        <source src="video/Motion.mp4" type="video/mp4" />
    </video>
    <div class="overlay">
        <p>Content above your video</p>
        <form>
            <p>Content Below Your Video</p>
            <label for="input">Form Input Label</label>
            <input id="input" name="input" value="" />
            <button type="submit">Submit</button>
        </form>
    </div>
</div>

If you want to put the content on top of the video, you would use some kind of positioning:

如果你想把内容放在视频的顶部,你会使用某种定位:

.container { position:relative; }
.container video {
    position:relative;
    z-index:0;
}
.overlay {
    position:absolute;
    top:0;
    left:0;
    z-index:1;
}

回答by Abdul Basit

You can use top and left position to be in percentage. as it will auto adjust top text when the window content size will change

您可以使用顶部和左侧位置来表示百分比。因为当窗口内容大小改变时它会自动调整顶部文本

<div class="container">
    <video id="video" width="770" height="882" onclick="play();">
        <source src="video/Motion.mp4" type="video/mp4" />
    </video>
    <div class="overlayText">
        <p id="topText">Content above your video</p>
    </div>
</div>`enter code here`

#overlayText {
 position:absolute;
  top:30%;
  left:20%;
  z-index:1;
}

#topText {
  color: white;
  font-size: 20px;
  align-self: center;
}