热搜: 活动 交友 discuz
查看: 194|回复: 1

马黑黑《纯CSS实现卡片正背两面翻转》

[复制链接]
发表于 2026-8-29 21:34:46 | 显示全部楼层 |阅读模式
<style>
    /* body创建景深 :800px */
    body {
        font-size: 2em;
        perspective: 800px;
    }
    /* 容器 :提供3d场景 */
    .pa {
        width: 460px;
        height: 200px;
        transform-style: preserve-3d;
        margin: auto;
        margin-top: 200px;
        position: relative;
    }
    /* 子元素做3d转换 */
    .son {
        width: 100%;
        height: 100%;
        background: linear-gradient(45deg, lightblue, beige);
        box-shadow: 2px 2px 16px rgba(0, 0, 0, .25);
        backface-visibility: hidden; /* 背面朝向观察者时不可见 */
        /*transform: rotate3d(0, 0, 0, 0);*/
        transition: transform 1.2s;
        display: grid;
        place-items: center;
        position: absolute;
    }
    /* 第二个子元素背对观察者(注意角度为负数以确保转向衔接)*/
    .son:nth-of-type(2) {
        transform: rotate3d(0, 1, 0, -180deg);
    }
    /* 容器鼠标滑入 :第一个子元素背对观察者 */
    .pa:hover .son:nth-of-type(1) {
        transform: rotate3d(0, 1, 0, 180deg);
    }
    /* 容器鼠标滑入 :第二个子元素正对观察者 */
    .pa:hover .son:nth-of-type(2) {
        transform: rotate3d(0, 0, 0, 0deg);
    }
</style>

<div class="pa">
    <div class="son">恭喜您中奖啦!</div>
    <div class="son">中奖金额 :¥6666.66</div>
</div>

200

主题

1139

回帖

1万

积分

社区贵宾

积分
16110

最佳新人活跃会员热心会员推广达人宣传达人灌水之王突出贡献

发表于 2026-9-1 17:59:31 | 显示全部楼层
实用的教程,谢谢分享
该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|小黑屋|纳兰音画网 ( 蜀ICP备2021011087号-1 )

GMT+8, 2026-11-16 08:21 , Processed in 0.052653 second(s), 21 queries .

Powered by Discuz! X5.0

© 2001-2020 Comsenz Inc.

快速回复 返回顶部 返回列表