目录
一、正方体
二、动态立体图片册
三、平面的星空
首页 web前端 css教程 纯CSS实现3D的代码(正方体、动态立体图片册、平面的星空)

纯CSS实现3D的代码(正方体、动态立体图片册、平面的星空)

Aug 14, 2018 pm 04:55 PM

本篇文章所说的内容是纯CSS实现3D的代码(正方体、动态立体图片册、平面的星空),代码都非常详细,有需要的朋友可以看一下。

一、正方体

我认为正方体可以算是3D图像的基础吧,首先正方体是由六个相同的面所组成,其次就需要我们依次构造。(据体构造在代码中)

代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>正方体</title>
<style>
    .d3{
        height: 300px;
        width:300px;
        perspective: 800px;
        margin:140px auto;
        border:1px solid #ccc;    }
    .stage{
        height: 300px;
        width: 300px;
        transform-style: preserve-3d;
        
        position: relative;
        transform: rotateX(45deg) rotateY(45deg);
        
    }
    .role{
        height: 300px;
        width: 300px;
        position: absolute;
    }
    .stage{
        animation: dong 3s linear infinite;(这是舞台)

    }
    .stage:hover{
        animation: paused;
    }
    @keyframes dong{(这是使舞台旋转的动画)
        from{
        transform: rotateX(45deg) rotateY(45deg);            
        }
        to{
        transform: rotateX(405deg) rotateY(405deg);
        }
    }
    .di1{(正方体的前面)
        background: rgb(21, 163, 52);
        transform: translateZ(150px);(沿着z轴向前移动150px)
        font-size:100px;
        font-family:KaiTi;
        text-align: center;
        line-height: 300px;
    }
    .di2{(正方体的后面)
        background: blue;
        transform: translateZ(-150px) rotateY(180deg);(沿着z轴向前移动150px然后沿着y轴旋转180°*注意顺序哦是先移动后旋转)
        font-size:100px;
        font-family:KaiTi;
        text-align: center;
        line-height: 300px;
    }
    .di3{(正方体的左面)
        background: purple;
        transform: rotateY(-90deg) translateZ(150px);
        font-size:100px;
        font-family:KaiTi;
        text-align: center;
        line-height: 300px;
    }
    .di4{(正方体的右面)
        background: pink;
        transform: rotateY(90deg) translateZ(150px);
        font-size:100px;
        font-family:KaiTi;
        text-align: center;
        line-height: 300px;
    }
    .di5{(正方体的上面)
        background: red;
        transform: rotateX(90deg) translateZ(150px);
        font-size:100px;
        font-family:KaiTi;
        text-align: center;
        line-height: 300px;
    }
    .di6{(正方体的下面)
        background: yellow;
        transform: rotateX(-90deg) translateZ(150px);
        font-size:100px;
        font-family:KaiTi;
        text-align: center;
        line-height: 300px;
    }
</style>
</head>
<body>
    <div>
        <div>
        (将正方体分为六个相同的面)
            <div class="role di1">前</div>
            <div class="role di2">后</div>
            <div class="role di3">左</div>
            <div class="role di4">右</div>
            <div class="role di5">上</div>
            <div class="role di6">下</div>
        </div>
    </div>
</body>
</html>
登录后复制

二、动态立体图片册

将图片册设计成立体3D的效果

利用旋转、移动、倾斜和3D效果让你的图册更加漂亮。
代码如下:

(将第一张定好位置后将后面的依次排列)
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>事例一</title>
    <style>
        body{
            height: 100vh;
        }
        .div {
            height: 500px;
            width: 800px;
            perspective: 800px;
            margin: 50px auto;
        }

        .div1 {
            height: 500px;
            width: 800px;
            transform-style: preserve-3d;
            position: relative;
            /* transform: rotateY(-10deg); */
        }
        .div_0{
            height:400px;
            width:600px;
            position: absolute;
            margin-top:110px;
            margin-left:50px;
        }
        .div_1{
            height:400px;
            width:600px;
            background: url(../day03/timg.jpg);
            background-size: 600px 400px;
            border-radius: 20px;
            transform-origin: right bottom;
            transition: 3s;
        }

        .div_2{
            background: url(../day03/timg1.jpg);
            border-radius: 20px;
            background-size: 600px 400px;
            transform-origin: right bottom;
            transform: rotateZ(2deg) translateZ(-20px) translateX(20px) translateY(-20px);
        }
        .div_2:hover{
            transform: rotateZ(0) translateZ(0)translateX(0)translateY(0);
            transition: 1s;
        }
        .div_2:hover~.div_1{
            /* transform-origin: right bottom; */
            transform: rotateZ(2deg) translateZ(20px) translateX(20px) translateY(-20px);
            transition: 1s;
        }
        /* body:hover .div_1{
            opacity: 0;
            transition: 3s;
        } */

        .div_3{
            background: url(timg2.jpg);
            border-radius: 20px;
            background-size: 600px 400px;
            transform-origin: right bottom;
            transform: rotateZ(4deg)translateZ(-40px)translateX(40px)translateY(-40px);

        }
        .div_3:hover{
            transform: rotateZ(0) translateZ(0)translateX(0)translateY(0);
            transition: 1s;
        }
        .div_4{
            background: url(timg4.jpg);
            border-radius: 20px;
            background-size: 600px 400px;
            transform-origin: right bottom;
            transform: rotateZ(6deg)translateZ(-60px) translateX(60px)translateY(-60px);
            
        }
        .div_4:hover{
            transform: rotateZ(0) translateZ(0)translateX(0)translateY(0);
            transition: 1s;
        }
        .div_5{
            background: url(timg5.jpg);
            border-radius: 20px;
            background-size: 600px 400px;
            transform-origin: right bottom;
            transform: rotateZ(8deg)translateZ(-80px) translateX(80px)translateY(-80px);
        }
        .div_5:hover{
            transform: rotateZ(0) translateZ(0)translateX(0)translateY(0);
            transition: 1s;
        }
        .div_6{
            background: url(timg3.jpg) no-repeat;
            border-radius: 20px;
            background-size: 600px 400px;
            transform-origin: right bottom;
            transform: rotateZ(10deg)translateZ(-100px) translateX(100px)translateY(-100px);
        }
        .div_6:hover{
            transform: rotateZ(0) translateZ(0)translateX(0)translateY(0);
            transition: 1s;
        }
    </style>
</head>

<body>
    <div>
        <div>
            <div class=" div_0 div_1"></div>
            <div class=" div_0 div_2"></div>
            <div class=" div_0 div_3"></div>
            <div class=" div_0 div_4"></div>
            <div class=" div_0 div_5"></div>
            <div class=" div_0 div_6"></div>
        </div>
    </div>
</body>

</html>
登录后复制

三、平面的星空

代码如下:
(由于没有用js所以只有平面的效果了
你掌握好旋转的中心点就很容易了)

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>太阳系</title>
<style>
    body {
        background: url(timg01.jpg) no-repeat;
        background-size: 100%;
    }

    .box1 {
        height: 600px;
        width: 600px;
        margin: 0 auto;
        border: 1px solid #ccc;
        border-radius: 50%;
    }

    .box1_0 {
        height: 100px;
        width: 100px;
        margin: 0 auto;
        border: 1px solid white;
        border-radius: 50%;
        position: absolute;
        top: calc(50% - 59px);
        left: 322px;
        transform-origin: 345.5px;
        animation: dong2 5s linear infinite 4s;
    }

    @keyframes dong2 {
        from {
            transform: rotate(0)
        }
        100% {
            transform: rotate(360deg);
        }
    }

    .box1_2 {
        height: 13px;
        width: 13px;
        margin: 0 auto;
        /* border: 1px solid #ccc; */
        border-radius: 50%;
        background: white;
        position: absolute;
        top: calc(50% - 7.5px);
        left: 96px;
        transform-origin: -45px;
        animation: dong3 5.5s linear infinite ;
        /* animation-iteration-count: 200; */
    }

    @keyframes dong3 {
        from {
            transform: rotate(0);
        }
        100% {
            transform: rotate(360deg);
        }
    }

    .box1_1 {
        height: 15px;
        width: 15px;
        margin: 0 auto;
        /* border: 1px solid #ccc; */
        border-radius: 50%;
        background: rgb(7, 100, 223);
        position: absolute;
        top: 45px;
        left: calc(50% - 16.5px);
    }

    .box2 {
        height: 400px;
        width: 400px;
        margin: 0 auto;
        border: 1px solid #ccc;
        border-radius: 50%;
        position: absolute;
        top: calc(50% - 200px);
        left: calc(50% - 200px);
    }

    .box2_1 {
        height: 15px;
        width: 15px;
        margin: 0 auto;
        /* border: 1px solid #ccc; */
        border-radius: 50%;
        background: rgb(198, 208, 221);
        position: absolute;
        top: calc(50% - 7.5px);
        left: 43px;
        transform-origin: 157.5px;
        animation: dong1 5s linear infinite .5s;

    }

    @keyframes dong1 {
        from {
            transform: rotate(0)
        }
        100% {
            transform: rotate(360deg);
        }
    }

    .box2_2 {
        height: 15px;
        width: 15px;
        margin: 0 auto;
        border-radius: 50%;
        background: #644e11;
        position: absolute;
        top: calc(50% - 7.5px);
        left: -7px;
        transform-origin: 207.5px;
        animation: dong 5s linear infinite;
    }

    @keyframes dong {
        from {
            transform: rotate(0)
        }
        100% {
            transform: rotate(360deg);
        }
    }

    .box3 {
        height: 300px;
        width: 300px;
        margin: 0 auto;
        border: 1px solid #ccc;
        border-radius: 50%;
        position: absolute;
        top: calc(50% - 150px);
        left: calc(50% - 150px);
    }

    .box4 {
        height: 30px;
        width: 30px;
        margin: 0 auto;
        border-radius: 50%;
        background: orange;
        position: absolute;
        top: calc(50% - 15px);
        left: calc(50% - 15px);
    }
    .boxli{
        height: 900px;
        width: 900px;
        margin: 0 auto;
        border: 1px solid #ccc;
        border-radius: 50%;
       position: absolute;
       top:-120px;
       left:calc(50% - 450px);
        
    }
    .boxli_1{
        height: 15px;
        width: 15px;
        margin: 0 auto;
        border-radius: 50%;
        background: rgb(116, 100, 56);
        position: absolute;
        top:500px;
       left:-6px;
       transform-origin: 455.5px -38px;
        animation: dongli 5s linear infinite;
    }
    @keyframes dongli {
        from {
            transform: rotate(0)
        }
        100% {
            transform: rotate(360deg);
        }
    }
</style>
</head>
<body>
    <div class="box1">
        <div class="box1_0">
            <div class="box1_2"></div>
            <div class="box1_1"></div>
        </div>
        <div class="box2">
            <div class="box2_1"></div>
            <div class="box2_2"></div>
            <div class="box3">
                <div class="box4"></div>
            </div>
        </div>
    </div>
    <div class="boxli">
        <div class="boxli_1"></div>
</div>
</body>
</html>
登录后复制

相关推荐:

css怎么实现卡片图像翻转效果?(特效示例)

css3D+动画的例子(附完整代码)

以上是纯CSS实现3D的代码(正方体、动态立体图片册、平面的星空)的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.聊天命令以及如何使用它们
1 个月前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

使用GraphQL缓存 使用GraphQL缓存 Mar 19, 2025 am 09:36 AM

如果您最近开始使用GraphQL或审查了其优点和缺点,那么您毫无疑问听到了诸如“ GraphQl不支持缓存”或

使用Redwood.js和Fauna构建以太坊应用 使用Redwood.js和Fauna构建以太坊应用 Mar 28, 2025 am 09:18 AM

随着最近比特币价格超过20k美元的攀升,最近打破了3万美元,我认为值得深入研究创建以太坊

用高架创建自己的野蛮人 用高架创建自己的野蛮人 Mar 18, 2025 am 11:23 AM

无论您是开发人员的哪个阶段,我们完成的任务(无论大小)都会对我们的个人和专业成长产生巨大影响。

VUE 3 VUE 3 Apr 02, 2025 pm 06:32 PM

它的出局!恭喜Vue团队完成了完成,我知道这是一项巨大的努力,而且很长时间。所有新文档也是如此。

您可以从浏览器获得有效的CSS属性值吗? 您可以从浏览器获得有效的CSS属性值吗? Apr 02, 2025 pm 06:17 PM

我有人写了这个非常合法的问题。 Lea只是在博客上介绍了如何从浏览器中获得有效的CSS属性。那样的是这样。

在CI/CD上有点 在CI/CD上有点 Apr 02, 2025 pm 06:21 PM

我说的“网站”比“移动应用程序”更合适,但我喜欢Max Lynch的框架:

比较浏览器的响应式设计 比较浏览器的响应式设计 Apr 02, 2025 pm 06:25 PM

这些桌面应用程序中有许多目标是同时在不同的维度上显示您的网站。因此,例如,您可以写作

带有粘性定位的堆叠卡和一点点的杂物 带有粘性定位的堆叠卡和一点点的杂物 Apr 03, 2025 am 10:30 AM

前几天,我发现了科里·金尼文(Corey Ginnivan)网站上的这一点,当您滚动时,彼此之间的卡片堆放集。

See all articles