2013-02-05 48 views
0

試圖找出如何利用CSS動畫並重疊元素。使用CSS重疊divtags

Demo site

基本上我DIV叫史蒂芬坐一半的DIV地面頂部和一半的股利被稱爲月亮之上(具有動畫)

頁:

 <style> 

     body { 
      background-repeat: no-repeat; 
      background: -moz-linear-gradient(top, #1e5799 0%, #2989d8 50%, #207cca 51%, #7db9e8 100%); /* FF3.6+ */ 
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(50%,#2989d8), color-stop(51%,#207cca), color-stop(100%,#7db9e8)); /* Chrome,Safari4+ */ 
      background: -webkit-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Chrome10+,Safari5.1+ */ 
      background: -o-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* Opera 11.10+ */ 
      background: -ms-linear-gradient(top, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* IE10+ */ 
      background: linear-gradient(to bottom, #1e5799 0%,#2989d8 50%,#207cca 51%,#7db9e8 100%); /* W3C */ 
      filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#1e5799', endColorstr='#7db9e8',GradientType=0); /* IE6-9 */ 
      height: 100%; 
      margin: 0; 
      background-repeat: no-repeat; 
      background-attachment: fixed; 
      -webkit-animation: sky-to-black 5s ease forwards; 
      -moz-animation: sky-to-black 5s ease forwards; 
      -ms-animation:  sky-to-black 5s ease forwards; 
     } 
     .ground { 
      position: relative; 
      top: 50%; 
      left: 0; 
      width: 100%; 
      height: 50%; 
      background: black; 
      -webkit-animation: ground-to-black 5s ease forwards; 
      -moz-animation: ground-to-black 5s ease forwards; 
      -ms-animation:  ground-to-black 5s ease forwards; 
     } 
     .moon { 
      width: 100px; 
      height: 100px; 
      position: absolute; 
      background: white; 
      border-radius: 0px; 
      box-shadow: 0 0 20px white; 
      left: 50%; 
      top: 80%; 
      margin: 0 -50px; 
      -webkit-animation: rising-sun 5s ease forwards; 
      -moz-animation: rising-sun 5s ease forwards; 
      -ms-animation:  rising-sun 5s ease forwards; 
     } 

     .ground, .moon { 
      text-indent: -9999px; 
      overflow: hidden; 
     } 

     @-moz-keyframes rising-sun { 
      0% { 
       top: 80%; 
       box-shadow: 0 0 20px 100px white; 
      } 
      100% { 
       top: 15%; 
       box-shadow: 0 0 150px 20px white; 
      } 
     } 
     @-webkit-keyframes rising-sun { 
      0% { 
       top: 80%; 
       box-shadow: 0 0 20px 100px white; 
      } 
      100% { 
       top: 15%; 
       box-shadow: 0 0 150px 20px white; 
      } 
     } 
     @-ms-keyframes rising-sun { 
      0% { 
       top: 80%; 
       box-shadow: 0 0 20px 100px white; 
      } 
      100% { 
       top: 15%; 
       box-shadow: 0 0 150px 20px white; 
      } 
     } 

     @-moz-keyframes sky-to-black { 
      0% { 
       background-color: #133d48; 
      } 
      100% { 
       background-color: black; 
      } 
     } 
     @-moz-keyframes ground-to-black { 
      0% { 
       background-color: #211d11 
      } 
      100% { 
       background-color: black; 
      } 
     } 
     @-webkit-keyframes sky-to-black { 
      0% { 
       background-color: #133d48; 
      } 
      100% { 
       background-color: black; 
      } 
     } 
     @-webkit-keyframes ground-to-black { 
      0% { 
       background-color: #211d11 
      } 
      100% { 
       background-color: black; 
      } 
     } 
     @-ms-keyframes sky-to-black { 
      0% { 
       background-color: #133d48; 
      } 
      100% { 
       background-color: black; 
      } 
     } 
     @-ms-keyframes ground-to-black { 
      0% { 
       background-color: #211d11 
      } 
      100% { 
       background-color: black; 
      } 
     } 

    #Central { 
    width: 100%; 

    } 

    #Steve { 

     width: 500px; 
     height:500px; 
     background: #fff; 
     margin-top: 250px; 
     position:relative; 


    } 
    </style> 

<div id="container">  
<div class="moon"> 
</div> 
<div id="Central" style="color: #fff; width:100%; Text-align: Center;"><h1>Welcome to my Minecraft Mods!</h1></div> 
<div id="Steve"></div> 
<div class="ground"> 
</div> 
</div> 

問題:

爲什麼我不能用白色盒子獲得那個div標籤,坐在中間的所有東西之上?

+0

你能否提供一個更小的演示來展示你正在努力克服的問題?另外,你的問題是什麼? – KatieK

+0

我相信演示正確解釋了這個問題,我編輯了問題 –

回答

0

我脫掉了左邊的值和邊距,它靠近了。完全不確定。對於那種特定的位置,我不會使用基於%的值。獲取高度,並計算如果你最通過jquery,但真的,只需使用CSS來定位它將像素會更容易。

+0

用Z-index來修復它。這使我可以對網站進行分層 –