0

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

演示站点

本质上,我 div 叫 Steven,让他一半坐在 div 地面上,一半坐在名为 moon 的 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 标签放在中间的所有内容之上?

4

1 回答 1

0

我去掉了左边的值和边距,它变得更近了。不太确定。对于那种特定的位置,我不会使用基于百分比的值。获取高度并计算您是否最常通过 jquery 进行计算,但实际上,仅使用 css 来定位像素会更容易。

于 2013-02-06T00:02:13.563 回答