2017-10-15 41 views
0

我发现代码在网上,我复制到让我的网站的标题在一个环形的背景视频。但是,我在屏幕左侧添加链接的工作无效。因为我希望每个人都堆叠在另一个之上,所以我认为flexbox是最好的处理方式,但我甚至不能在没有它的情况下显示链接。我做错了什么,达成目标的最佳方法是什么?的z-index不是文字工作过的背景视频

body { 
 
    width: 100%; 
 
    margin: 0 auto 0; 
 
} 
 

 
.video_main { 
 
    margin: 0 auto 0; 
 
    width: 100%; 
 
    height: auto; 
 
    overflow: hidden; 
 
} 
 

 
.video_main video { 
 
    /*width: 100%;*/ 
 
    width: 100%px; 
 
    height: auto; 
 
    min-width: 720px; 
 
    margin: 0 auto; 
 
    z-index: -1500; 
 
} 
 

 
.content h1 { 
 
    font-family: "jaf-domus-titling-web", sans-serif; 
 
    color: white; 
 
    text-align: center; 
 
    font-size: 48px; 
 
    letter-spacing: 4px; 
 
    z-index: 100; 
 
    position: absolute; 
 
    top: 75px; 
 
} 
 

 
.content h2 { 
 
    font-family: "europa", sans-serif; 
 
    color: white; 
 
    text-align: center; 
 
    font-size: 30px; 
 
    letter-spacing: 6px; 
 
    z-index: 100; 
 
    position: absolute; 
 
    top: 175px; 
 
} 
 

 
.content p { 
 
    display: block; 
 
    font-family: "europa", sans-serif; 
 
    color: white; 
 
    text-align: center; 
 
    font-size: 16px; 
 
    z-index: 100; 
 
    position: absolute; 
 
} 
 

 
h1 { 
 
    width: 100%; 
 
} 
 

 
h2 { 
 
    width: 100%; 
 
}
<div class="video_main"> 
 
    <video width="100%" height="100%" autoplay="autoplay" loop="loop" muted="muted" preload> 
 
    <source src="http://bartonlewisfilm.com/red hook, rush hour (excerpt).mp4" type="video/mp4"> 
 
     </video> 
 
    <div class="content"> 
 
    <h1>Barton Lewis</h1> 
 
    <h2>films about light and the urban landscape</h2> 
 
    <p><a href="index.html" title="home">home</a></p> 
 
    <p><a href="bartons_film_site_works.html" title="works">works</a></p> 
 
    <p><a href="bartons_film_site_bio.html" title="bio">bio</a></p> 
 
    <p><a href="bartons_film_site_cv.html" title="c/v">CV</a></p> 
 
    <p><a href="bartons_film_site_contact.html" title="contact">contact</a></p> 
 
    </div> 
 
</div>

+0

当你说你要链接添加到屏幕的左侧,这听起来像你的意思视频旁边 - 但是你的标题是关于文本在背景视频,所以你的意思是要他们出示过视频向左下方? – FluffyKitten

+0

是的,这是正确的,抱歉的混淆。我希望链接显示在视频上方,就像网站标题的上方和中心一样。 –

回答

0

的问题是不是z-index的,其你是不是在定位在首位的视频的链接。

您已经为<p>元素absolute设置了位置,但您还没有告诉它其中需要对它们进行定位。您需要使用顶部,底部,左侧和/或右侧放置元素。

而不是做这为每个<p>元素,其更容易将其全部添加到一个div,然后就立场,即一个DIV。

1:组链接到一个div更容易定位,如:

<div class="content"> 
     <h1>Barton Lewis</h1> 
     <h2>films about light and the urban landscape</h2> 
     <div class="videolinks"> 
      <p><a href="index.html" title="home">home</a></p> 
      [etc...] 
     </div> 
    </div> 

2:.content p取下定位,因为我们将使用div来放置它们

.content p { 
    [...] 
    position:absolute; /* <- REMOVE */ 
} 

3:创建您的CSS规则来定位div,例如

.content .videolinks{ 
    position:absolute; 
    top:20px; 
    left:20px; 
    z-index:100; 
} 


工作段:

body { 
 
    width: 100%; 
 
    margin: 0 auto 0; 
 
    } 
 
.video_main { 
 
    margin:0 auto 0; 
 
    width:100%; 
 
    height:auto; 
 
    overflow: hidden; 
 
} 
 
.video_main video { 
 
    /*width: 100%;*/ 
 
    width: 100%px; 
 
    height: auto; 
 
    min-width: 720px; 
 
    margin: 0 auto; 
 
    z-index:-1500; 
 
    } 
 
.content h1 { 
 
    font-family: "jaf-domus-titling-web",sans-serif; 
 
    color: white; 
 
    text-align: center; 
 
    font-size: 48px; 
 
    letter-spacing: 4px; 
 
    z-index:100; 
 
    position:absolute; 
 
    top:75px; 
 
} 
 
.content h2 { 
 
    font-family: "europa",sans-serif; 
 
    color: white; 
 
    text-align: center; 
 
    font-size: 30px; 
 
    letter-spacing: 6px; 
 
    z-index:100; 
 
    position:absolute; 
 
    top:175px; 
 
    } 
 
.content p { 
 
    font-family: "europa",sans-serif; 
 
    color: white; 
 
    font-size: 16px; 
 
    } 
 
.content .videolinks{ 
 
    position:absolute; 
 
    top:20px; 
 
    left:20px; 
 
    z-index:100; 
 
    } 
 
h1 { 
 
    width: 100%; 
 
    } 
 
h2 { 
 
    width: 100%; 
 
    }
<div class="video_main"> 
 
    <video width="100%" height="100%" autoplay="autoplay" loop="loop" muted="muted" preload> 
 
<source src="http://bartonlewisfilm.com/red hook, rush hour (excerpt).mp4" type="video/mp4"> 
 
    </video> 
 
    <div class="content"> 
 
     <h1>Barton Lewis</h1> 
 
     <h2>films about light and the urban landscape</h2> 
 
     <div class="videolinks"> 
 
      <p><a href="index.html" title="home">home</a></p> 
 
      <p><a href="bartons_film_site_works.html" title="works">works</a></p> 
 
      <p><a href="bartons_film_site_bio.html" title="bio">bio</a></p> 
 
      <p><a href="bartons_film_site_cv.html" title="c/v">CV</a></p>   
 
      <p><a href="bartons_film_site_contact.html" title="contact">contact</a></p> 
 
     </div> 
 
    </div> 
 
    </div>

不要忘记,你可能需要调整视频标题等的位置,以腾出空间的联系,特别是在小屏幕上。

+0

非常感谢!最后一个问题是:在我复制的代码中,没有为“video_main”元素设置定位,但声明了z-index。 z-index和定位不总是一起吗? –

+0

@BartonLewis“*不要z-索引和定位一定要同时*?” - 是的,你是正确的。在“.video_main视频”的z-index的是没有因为任何作用,但它不是必需的,因为你的其他元素有较高的z-index不是默认的反正。 FYI有在代码中的一些其他错误太(我只是在看你的固定链接) - 例如,你也有“宽度:** 100%PX **”,在“.video_main视频”。你真的在检查和质疑你复制的代码,而不是盲目地复制它 - 这并不是你在互联网上得到的所有东西都是正确的! :) – FluffyKitten

+0

再次感谢和捕捉其他错误。多谢, –