欢迎光临
我们一直在努力

Web前端教程:3D图片旋转魔方特效纯CSS样式

3D图片旋转魔方特效纯CSS样式,废话不多说直接上代码。效果图如下:

html部分:

<!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图片旋转魔方特效纯CSS样式</title>?
        <link rel="stylesheet" href="index.css">
    </head>
    <body>
        <!-- 快捷输入指令: ?section>div*6>img[src="images/$.jpg"] ? ?然后按tab键
? ? 导入准备好的图片-->
        ? ? <section>
            
            ? ? ? ? <div><img src="img/1.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/2.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/3.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/4.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/5.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/6.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/1.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/2.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/3.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/4.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/5.jpg" alt=""></div>
            ? ? ? ? <div><img src="img/6.jpg" alt=""></div>
            ? ? </section>
            
    </body>
</html>

 

css样式:

 * {
    padding: 0;
    margin: 0;
}
body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background-color: black;
    perspective: 1000px;
}
section {
    position: relative;
    width: 150px;
    height: 150px;
    transform-style: preserve-3d;
    animation: rotate 5s linear infinite;
}
section div {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #fff;
    transition: all 1s;
}
section div img {

    width: 100%;

    height: 100%;

}
section div:nth-child(1) {
    transform: translateZ(75px);
}
section:hover div:nth-child(1) {
    transform: translateZ(200px);
}
section div:nth-child(2) {
    transform: rotateX(-180deg) translateZ(75px);
}
section:hover div:nth-child(2) {
    transform: rotateX(-180deg) translateZ(200px);
}
section div:nth-child(3) {
    transform: rotateX(90deg) translateZ(75px);
}
section:hover div:nth-child(3) {
    transform: rotateX(90deg) translateZ(200px);
}

section div:nth-child(4) {
    transform: rotateX(-90deg) translateZ(75px);
}
section:hover div:nth-child(4) {
    transform: rotateX(-90deg) translateZ(200px);
}
section div:nth-child(5) {
    transform: rotateY(90deg) translateZ(75px);
}
section:hover div:nth-child(5) {
    transform: rotateY(90deg) translateZ(200px);
}
section div:nth-child(6) {
    transform: rotateY(-90deg) translateZ(75px);
}
section:hover div:nth-child(6) {
    transform: rotateY(-90deg) translateZ(200px);
}
section div:nth-child(7) {
    transform: translateZ(75px);
}
section div:nth-child(8) {
    transform: rotateX(-180deg) translateZ(75px);
}
section div:nth-child(9) {

    transform: rotateX(90deg) translateZ(75px);
}
section div:nth-child(10) {
    transform: rotateX(-90deg) translateZ(75px);
}
section div:nth-child(11) {
    transform: rotateY(90deg) translateZ(75px);
}
section div:nth-child(12) {
    transform: rotateY(-90deg) translateZ(75px);
}
@keyframes rotate {
    0% {
        transform: rotateY(0) rotateX(0);
    }
    100% {
        transform: rotateY(360deg) rotateX(360deg);
    }
}

 






文件名称:3D图片旋转魔方特效纯CSS样式

更新日期:2022-05-29

文件大小:120Kb

提示:如有问题、侵权或者下载链接失效请联系站长!邮箱:xinqidianblog@163.com

点击下载

赞(0) 打赏
未经允许不得转载:新起点博客 » Web前端教程:3D图片旋转魔方特效纯CSS样式
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏