简体   繁体   English

透视CSS3无法正常工作

[英]Perspective CSS3 Not Working

I am trying to develop a card flip animation in X axis direction. 我正在尝试在X轴方向上开发卡片翻转动画。 As of now, div now simply rotates using rotateX() method. 截至目前, div现在仅使用rotateX()方法进行旋转。 I have tried using perspective property to the upper div, instead of working it distorts my div structure. 我尝试对上层div使用Perspective属性,而不是对其进行操作会扭曲我的div结构。 Since, it is just a working stage, I am only targeting google chrome. 因为这只是一个工作阶段,所以我只针对Google chrome。 Please see it on codepen . 请在codepen上看到它。

Here is my HTML code. 这是我的HTML代码。

<div class="wrapper">
                <div class="upper">
                    <div class="upper-current">
                        <div class="content">
                            1
                        </div>
                    </div>
                    <div class="upper-next">
                        <div class="content">
                            2
                        </div>
                    </div>
                </div>

                <div class="lower">
                    <div class="lower-current">
                        <div class="content">
                            1
                        </div>
                    </div>
                    <div class="lower-next">
                        <div class="content">
                            2
                        </div>
                    </div>
                </div>
            </div>

And my CSS, div.row{ width: 150px; 还有我的CSS,div.row {width:150px; height: 200px; 高度:200px; margin: 0 auto; 保证金:0自动; } }

        div.wrapper{
            background-color: #444;
            width: 150px;
            height: 200px;
            border-radius: 5px;
            position:relative;

        }

        div.wrapper div.upper, div.wrapper div.lower{
            height: 100px;
            width:100%;

        }

        div.upper-current{
            transition :all 1s;
            transform-origin: 50% 100%;
        }

        div.wrapper > div.upper > div, div.wrapper > div.lower > div{
            height: 100px;
            width:100%;
            position:absolute;
            top:0;
            overflow:hidden;
            text-align:center;
            background-color:#444;
        }

        div.wrapper > div.upper > div{
            border-bottom: 3px solid #333;
        }

        div.wrapper > div.lower > div{
            height: 200px;
        }

        div.upper-current{
            z-index: 4;
        }

        div.upper-next{
            z-index: 3;
        }

        div.lower-current{
            z-index: 2;
        }

        div.lower-next{
            z-index: 1;
        }

        div.content{
            position: relative;
            top: -24px;
        }

I am trying to achieve this effect. 我正在努力达到这种效果。 顶部边缘较大,看起来像出来。

But with my code, I am simply gettting. 但是用我的代码,我简直就是傻瓜。 普通旋转效果。

UPDATE: This codepen should work on firefox, too. 更新:代码笔也应在firefox上工作。 Because of the stacking context problem, I just made .upper relative and gave it a z-index so it would be above .lower . 由于堆栈上下文问题,我只是将.upper relative ,并为其指定了z-index,使其位于.lower

If you put the perspective CSS property on .wrapper it should work: codepen 如果将perspective CSS属性放在.wrapper它应该可以工作: codepen

Perspective creates a new stacking context so if you put it on .upper , all of your upper <div> z-index 's are no longer in the same context as the lower ones and the lower ones are on top because of the natural HTML stacking. Perspective创建了一个新的堆栈上下文,因此,如果将其放在.upper ,由于自然的HTML,所有上面的<div> z-index不再与下面的上下文在同一上下文中,而下面的z-index在上面堆叠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM