项目文件结构截图

只需要一个html文件既可:

CSS环绕球体的旋转文字-3D效果_CSS

项目截图:

CSS环绕球体的旋转文字-3D效果_3d_02

代码实现原理:

该示例的实现过程很简单,主要是使用了CSS3的透视、3D旋转、位移、渐变、阴影,可以说是一次比较全面的练习。

HTML部分:

<div class="wrapper">
    <div class="ball"></div>
    <div class="stage">
        <div class="text">
            这里是文字
        </div>
    </div>
</div>

CSS部分:

使用到的CSS属性用法:

CSS环绕球体的旋转文字-3D效果_实现环绕球体_03

CSS环绕球体的旋转文字-3D效果_实现环绕球体_04

舞台:

* {
    margin: 0;
    padding: 0;
}
.wrapper {
    width: 400px;
    height: 400px;
    margin: 200px;
    perspective: 800px;
    perspective-origin: 50% 50%;
    position: relative;
}
.stage {
    transform-style: preserve-3d;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate3d(-50%, -50%, 0);
}

球体:

.ball {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background-color: #ccc;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate3d(-50%, -50%, 0);
    box-shadow: 0px 55px 45px -38px rgba(0, 0, 0, .3);
}
.ball::before {
    content: "";
    position: absolute;
    top: 1%;
    left: 5%;
    width: 90%;
    height: 90%;
    border-radius: 50%;
    background: -webkit-radial-gradient(50% 0px, circle, #ffffff, rgba(255, 255, 255, 0) 58%);
    z-index: 2;
}

文字:

.text {
    width: 100px;
    height: 50px;
    line-height: 50px;
    text-align: center;
    white-space: nowrap;
    animation: rotate 5s linear infinite;
    backface-visibility: hidden;
}

文字动画:

@keyframes rotate {
    from {
        transform: rotateY(0deg) translateZ(100px);
    }
    to {
        transform: rotateY(360deg) translateZ(100px);
    }
}

效果预览

效果地址:rotate-text-around-the-ball




阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: CSS