旋转的立方体

旋转立方体

html部分

用ul来表示整个立方体,用li来表示立方体的六个面

<div>
    <ul>
      <li>1</li>
      <li>2</li>
      <li>3</li>
      <li>4</li>
      <li>5</li>
      <li>6</li>
    </ul> 
</div>

为每个面设置不同的样式

li{
    font-size: 20px;
    line-height: 200px;
    text-align: center;
    list-style: none;
    position: absolute;   /* 防止正方体六个面位置错乱 */
    box-sizing: border-box;
    width: 200px;
    height: 200px;
    left: 0px;
    top: 0px;
    opacity: 0.5;
}




li:nth-child(1){
    background-color: lightblue;
    transform: translateZ(100px);
}
li:nth-child(2){
    background-color: lightcoral;
    transform: translateZ(-100px);
}
li:nth-child(3){
    background-color: lightgoldenrodyellow;
    transform: translateX(100px) rotateY(90deg);
}
li:nth-child(4){
    background-color: lightseagreen;
    transform: translateX(-100px) rotateY(90deg);
}
li:nth-child(5){
    background-color: lightpink;
    transform: translateY(100px) rotateX(90deg);
}
li:nth-child(6){
    background-color: lightgray;
    transform: translateY(-100px) rotateX(90deg);
}

让正方体立起来

ul{
    padding: 0px;

    position: relative;
    width: 200px;
    height: 200px;
    transform-style: preserve-3d;
    margin: 100px auto;

    transform: rotateX(-45deg) rotateY(-45deg);
}

通过旋转div使正方体转动

@keyframes rotate {
    0% {
        transform: rotateY(0deg);
    }

    100% {
        transform: rotateY(360deg)
    }
}

div{
    height: 400px;

    transform-style: preserve-3d;
    animation: rotate 5s infinite linear;
}

效果

在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值