HTML+CSS做出3D照片效果(HTML+CSS for 3D photo effect)

2022.10.14大家好,我最近看到一个关于用HTML+CSS实现的3D照片觉得非常好看,如图:

Hello everyone, I recently saw a 3D photo about using HTML+CSS and thought it was very nice, as shown in the picture:

 效果有点像魔方,而且可以翻转,具体如何实现,接下来就让我和大家说一说。

 The effect is a bit like a Rubik's cube, and it can be flipped. Let me tell you how to achieve it.

(1)创建HTML文件

Creating an HTML file

(2)编写div

write div

写六个div存放6张图片。

Write six DIVs for six images.

<div class="box">

        <div class="qian">
            <img src="./img/qian.jpg">
        </div>

        <div class="hou">
            <img src="./img/hou.jpg">
        </div>

        <div class="shang">
            <img src="./img/shang.jpg">
        </div>

        <div class="xia">
            <img src="./img/xia.jpg">
        </div>

        <div class="zuo">
            <img src="./img/zuo.jpg">
        </div>

        <div class="you">
            <img src="./img/you.jpg">
        </div>

    </div>

(3)编写CSS

write css

div {
    width: 300px;
    height: 300px;
}

.box {
    width: 300px;
    height: 300px;
    transform-style: preserve-3d;
    padding-left: 400px;
    padding-top: 300px;
    animation: move 50s linear infinite;
}

img {
    width: 300px;
    height: 300px;
}

.box:hover {
    transform: rotateX(360deg) rotateY(360deg);
}

.qian {
    background-color: pink;
    position: absolute;
    transform: translateZ(150px);
}

.hou {
    background-color: blue;
    position: absolute;
    transform: translateZ(-150px);
}

.shang {
    background-color: bisque;
    position: absolute;
    transform: translateY(-150px) rotateX(90deg);
}

.xia {
    background-color: aqua;
    position: absolute;
    transform: translateY(150px) rotateX(90deg);
}

.zuo {
    background-color: rebeccapurple;
    position: absolute;
    transform: translateX(-150px) rotateY(90deg);
}

.you {
    background-color: orange;
    position: absolute;
    transform: translateX(150px) rotateY(90deg);
}

div div {
    opacity: 0.9;
}

@keyframes move {
    0% {
        transform: rotateX(0) rotateY(0) rotateZ(0);
    }
    100% {
        transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
    }
}

.box:hover .qian {
    width: 300px;
    height: 300px;
    transform: translateZ(200px);
}

.box:hover .hou {
    width: 300px;
    height: 300px;
    transform: translateZ(-200px);
}

.box:hover .zuo {
    width: 300px;
    height: 300px;
    transform: translateX(-200px) rotateY(90deg);
}

.box:hover .you {
    width: 300px;
    height: 300px;
    transform: translateX(200px) rotateY(90deg);
}

.box:hover .shang {
    width: 300px;
    height: 300px;
    transform: translateY(200px) rotateX(90deg);
}

.box:hover .xia {
    width: 300px;
    height: 300px;
    transform: translateY(-200px) rotateX(90deg);
}

这样就可以实现3D照片的效果。

This allows you to create a 3D photo.

大家喜欢的话点个赞,支持一下!

If you like it, click a like and support it!

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

敲代码无敌小奶龙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值