3D骰子

CSS3 制作3D骰子

html:
<body>
<div id="box">
    <div class="box2">
        <div>上</div>
        <div>下</div>
        <div>左</div>
        <div>右</div>
        <div>前</div>
        <div>后</div>
    </div>
</div>
</body>
style:
<style type="text/css">
        *{
            padding: 0;
            margin: 0;
        }
        /*html,body{
            overflow: hidden;
            height: 100%;
        }*/
        #box{
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            margin: auto;
            width: 300px;
            height: 300px;
            border: 1px solid;

            /*景深(数值越大,越不明显)*/
            perspective: 2000px;
        }
        #box > .box2{
            position: absolute;
            top: 0;
            right: 0;
            bottom: 0;
            left: 0;
            margin: auto;
            width: 200px;
            height: 200px;

            /*动画时长*/
            transition: 3s;

            /*开启3D*/
            transform-style: preserve-3d;
            /*定位基点:(x,y,length)*/
            transform-origin: center center -100px;
        }
        #box > .box2 div{
            position: absolute;
            width: 200px;
            height: 200px;
            background-color: rgba(111,111,111,.8);
            font: 80px/200px "微软雅黑";
            text-align: center;

            /*影藏背面*/
            backface-visibility: hidden;
        }
        #box > .box2 > div:nth-child(1){
            top: -200px;
            transform-origin: bottom;
            transform: rotateX(90deg);
        }
        #box > .box2 > div:nth-child(2){
            top: 200px;
            transform-origin: top;
            transform: rotateX(-90deg);
        }
        #box > .box2 > div:nth-child(3){
            left: -200px;
            transform-origin: right;
            transform: rotateY(-90deg);
        }
        #box > .box2 > div:nth-child(4){
            left: 200px;
            transform-origin: left;
            transform: rotateY(90deg);
        }
        #box > .box2 > div:nth-child(5){
            /*‘前’面不用处理*/
            /*z-index: 1;*/
        }
        #box > .box2 > div:nth-child(6){
            /*‘后’面向Z轴向里面去200px*/
            transform: translateZ(-200px) rotateX(180deg);
        }
        #box:hover .box2{
            /*旋转父元素box2
             *三个参数(X,Y,Z)轴,再加上一个旋转的度数
             * */
            transform: rotate3d(3,2,1,360deg);
        }
    </style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值