纯css魔方

第一步

静态初始摆放

html

css

.C4 {
    perspective: 1000px;
    margin: 0 auto;
    width: 50%;
    height: 300px;
    background-color: #0a0400;
}

.C4>section div {
    width: 300px;
    height: 200px;
    position: absolute;
    top: 0;
    left: 0;
}

/* 最内部样式 */
.C4 section div:nth-child(1) {
    background: url(imege/动画1.jpg);
    background-size: 300px 200px;
    transform: translateZ(150px);
}

.C4 section div:nth-child(3) {
    background: url(imege/动画2.jpg.webp);
    background-size: 300px 200px;
    transform: rotateY(90deg) translateZ(150px);
}

.C4 section div:nth-child(5) {
    background: url(imege/动画3.jpg.webp);
    background-size: 300px 200px;
    transform: rotateY(180deg) translateZ(150px);
}

.C4 section div:nth-child(7) {
    background: url(imege/动画4.jpg);
    background-size: 300px 200px;
    transform: rotateY(-90deg) translateZ(150px);
}


.C4 section div:nth-child(9) {
    background: url(imege/动画5.jpg.webp);
    background-size: 300px 200px;
    transform: rotateX(90deg) translateZ(130px);
}

.C4 section div:nth-child(11) {
    background: url(imege/动画6.jpg);
    background-size: 300px 200px;
    transform: rotateX(-90deg) translateZ(130px);
}

/* 外部样式 */
.C4 section div:nth-child(2) {
    background-color: rgba(88, 43, 234, 0.5);
    width: 350px;
    height: 240px;
    transform: translateZ(200px);
    transition: all 3s;
}

.C4 section div:nth-child(4) {
    width: 350px;
    height: 240px;
    transform: rotateY(90deg) translateZ(200px);
    background-color: rgba(6, 237, 237, 0.5);
}

.C4 section div:nth-child(6) {
    background-color: rgba(180, 28, 28, 0.5);
    width: 350px;
    height: 240px;
    transform: rotateY(180deg) translateZ(200px);
}

.C4 section div:nth-child(8) {
    background-color: rgba(178, 184, 26, 0.5);
    width: 350px;
    height: 240px;
    transform: rotateY(-90deg) translateZ(200px);
}

.C4 section div:nth-child(10) {
    background-color: rgba(175, 59, 186, 0.5);
    width: 350px;
    height: 240px;
    transform: rotateX(90deg) translateZ(200px);
}

.C4 section div:nth-child(12) {
    background-color: rgba(71, 234, 46, 0.5);
    width: 350px;
    height: 240px;
    transform: rotateX(-90deg) translateZ(200px);
}

第二步

动态

在以上基础只改变了css


.C4>section {
    width: 300px;
    height: 200px;
    position: relative;
    margin: 300px auto;
    transform-style: preserve-3d;
    transform: rotateX(60deg);
    animation: mofang 10s linear infinite;
}

@keyframes mofang {
    0% {
        transform: rotateX(0) rotateY(0) rotateZ(0);
    }

    100% {
        transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
    }
}

第三步

触发特效

同上只改变css


/* 悬浮特效 */

.C4:hover {
    background-color: pink;
}

.C4:hover section>div:nth-child(2) {
    transition-duration: 1s;
    transform: translateZ(600px);
}

.C4:hover section>div:nth-child(4) {
    transition-duration: 1s;
    transform: rotateY(90deg) translateZ(600px);
}

.C4:hover section>div:nth-child(6) {
    transition-duration: 1s;
    transform: rotateY(180deg) translateZ(600px);
}

.C4:hover section>div:nth-child(8) {
    transition-duration: 1s;
    transform: rotateY(-90deg) translateZ(600px);
}

.C4:hover section>div:nth-child(10) {
    transition-duration: 1s;
    transform: rotateX(90deg) translateZ(600px);
}

.C4:hover section>div:nth-child(12) {
    transition-duration: 1s;
    transform: rotateX(-90deg) translateZ(600px);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值