zl程序教程

您现在的位置是:首页 >  其它

当前栏目

css3d实现两面翻转的盒子

实现 盒子 翻转
2023-06-13 09:12:15 时间
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title></title>
        <style>
            body{
                perspective: 500px;
            }
            .box{
                position: relative;
                width: 300px;
                height: 300px;
                margin: 100px auto;
                transform-style: preserve-3d;
                transition: all .4s;
                
            }
            .front,.back{
                position: absolute;
                top:0;
                left:0;
                width: 100%;
                height: 100%;
                border-radius: 50%;
                background-color: red;
                font-size: 30px;
                color:#fff;
                text-align: center;
                line-height: 300px;
            }
            .front{
                z-index: 1;
            }
            .back{
                background-color: antiquewhite;
                /* 使两个盒子背靠背 */
                transform: rotateY(180deg);
            }
            .box:hover{
                transform: rotateY(180deg);
            }
        </style>
    </head>
    <body>
        <div class="box">
            <div class="front">正面</div>
            <div class="back">反面</div>
        </div>
      
    </body>
</html>