简体   繁体   English

HTML5视频上方的H1文本

[英]H1 Text Above HTML5 Video

I have a background video and I would like to float text over the top of it. 我有一个背景视频,我想在其顶部浮动文字。 Currently it looks like this: 当前看起来像这样:

在此处输入图片说明

The green banner is the video and I would like the black heading text to float over the top of it. 绿色横幅是视频,我希望黑色标题文本浮在视频顶部。

Specifically, I would like the text to be aligned entered horizontally AND vertically. 具体来说,我希望将文本水平和垂直对齐。 So It looks like this: 所以看起来像这样:

在此处输入图片说明

Here is the code I have tried so far... 这是到目前为止我尝试过的代码...

HTML 的HTML

<div class="homepage-video">

        <video autoplay loop muted>
          <source src="https://player.vimeo.com/external/208845912.hd.mp4?s=2c04fe329c04029926a99943f076c84c6b86bb46&profile_id=119" type="video/mp4">
        </video>


        <div class="text-over-video">
            <h1>HEADING TEXT GOES HERE</h1>
        </div>

    </div>

CSS 的CSS

.homepage-video video {
    position:relative;
    width: 100%;
    height: auto;
    display:table;
    background-size: cover !important;
    background-repeat: no-repeat !important;
    background-position: 50% !important;

}

.text-over-video {
    text-align: center;
}

I've tried messing around with absolute and relative positioning and floating, I think to get the text entered I will need to add table elements? 我尝试弄乱绝对和相对定位以及浮动,我认为要输入文本,我需要添加表格元素吗?

I achieved this with help for header images here: http://ideedev.co.uk/newseed/design/ But I can't for the life of me get it working with the video... <<-- This is the part that is unique, I had already achieved it using images but I couldn't use the same approach with video. 我通过以下标题图片的帮助实现了这一目标: http : //ideedev.co.uk/newseed/design/但我一生都无法将其与视频配合使用... <<-独特的部分,我已经使用图像实现了,但是我不能对视频使用相同的方法。 This will helps someone if they are having the same issue. 如果某人遇到相同的问题,这将有所帮助。

You want to use absolute positioning, and you can use top: 50%; left: 50%; transform: translate(-50%,-50%); 您想使用绝对定位,并且可以使用top: 50%; left: 50%; transform: translate(-50%,-50%); top: 50%; left: 50%; transform: translate(-50%,-50%); to center it. 居中。

 .homepage-video, .homepage-video video { position: relative; } .homepage-video video { background-size: cover !important; background-repeat: no-repeat !important; background-position: 50% !important; } .text-over-video { position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); text-align: center; } 
 <div class="homepage-video"> <video autoplay loop muted> <source src="https://player.vimeo.com/external/208845912.hd.mp4?s=2c04fe329c04029926a99943f076c84c6b86bb46&profile_id=119" type="video/mp4"> </video> <div class="text-over-video"> <h1>HEADING TEXT GOES HERE</h1> </div> </div> 

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

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