html - 使用 CSS 重叠 div 标签

标签 html css animation

试图找出如何利用 CSS 动画并重叠元素。

Demo site

基本上我叫 Steven 的 div 一半坐在 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 标签位于中间所有内容的顶部?

最佳答案

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

关于html - 使用 CSS 重叠 div 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14718769/

相关文章:

Javascript 重复音频

html - 我怎样才能让三个不同高度的元素用css显示在同一行?

html - 禁用的输入字段在 safari 中无法正确呈现

jquery - Masonry 有时无法正确显示内容

wpf - 带百分比坐标的面板

c# - UserControl 动画按钮的背景

android - ViewPager fragment - 共享元素转换

html - 将滚动条添加到没有设置高度的 div

c# - Chrome 圆 Angular css?

html - 在 iOS 设备手指输入标签上滚动