0
点赞
收藏
分享

微信扫一扫

3D呈现transform-style及案例-两面翻转的盒子

一ke大白菜 2022-01-13 阅读 28
3dcsscss3

01-3D呈现transform-style

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>3D呈现transform-style</title>
    <style>
        body {
            perspective: 500px;
        }
        
        .box:hover {
            transform: rotateY(60deg);
        }
        
        .box {
            position: relative;
            width: 200px;
            height: 200px;
            margin: 100px auto;
            transition: all 2s;
            /* 让子元素开启3D立体空间 */
            transform-style: preserve-3d;
        }
        
        .box div {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: pink;
        }
        
        .box div:last-child {
            background-color: blue;
            transform: rotateX(60deg);
        }
    </style>
</head>

<body>
    <div class="box">
        <div></div>
        <div></div>

    </div>
</body>

</html>

效果展示

在这里插入图片描述

02-案例-两面翻转的盒子

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>两面翻转的盒子案例</title>
    <style>
        body {
            perspective: 400px;
        }
        
        .box {
            position: relative;
            width: 300px;
            height: 300px;
            margin: 100px auto;
            transition: all 2s;
            /* 让背面的紫色盒子开启立体空间,给父级添加 */
            transform-style: preserve-3d;
        }
        /* 鼠标一经过大盒子翻转 */
        
        .box:hover {
            transform: rotateY(180deg);
        }
        /* 两个前后的盒子罗列在一起,所以需要加定位 */
        
        .front,
        .back {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            border-radius: 50%;
            font-size: 30px;
            color: #fff;
            text-align: center;
            line-height: 300px;
        }
        
        .front {
            background-color: pink;
            z-index: 1;
        }
        
        .back {
            background-color: purple;
            /* 先让后面的盒子像手机一样背靠背旋转 */
            transform: rotateY(180deg);
        }
    </style>
</head>

<body>
    <!-- box父盒子里包含前后两个子盒子 -->
    <!-- box是翻转的盒子 -->
    <div class="box">
        <div class="front">黑马程序员</div>
        <div class="back">pink老师在等你</div>

    </div>
</body>

</html>

效果展示

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

举报

相关推荐

0 条评论