使用CSS重叠divtags

时间:2013-02-05 23:15:31

标签: html css animation

试图弄清楚如何利用CSS动画和重叠元素。

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标签放在中间的所有东西上?

1 个答案:

答案 0 :(得分:0)

我取下左边的值和边距,它越来越近了。真的不确定..对于那种特定的位置,我不会使用基于%的值。获取高度并通过jquery计算你是否最多,但实际上,只需使用css来定位像素就会更容易。