css3实现旋转太极图

话不多说,先看效果图:

这里写图片描述

实现过程如下:
1.首先放三个盒子,分别为大背景以及上面的两个小圆。

<div id="" class="divClass">
    <div id="" class="left">
    </div>
    <div id="" class="right">
    </div>
</div>

2.巧用border、after、before实现大背景图。

.divClass {
    border: 100px solid ;
    border-color: white white black black;      
    width: 0;
    height: 0;
    border-radius: 100%;
    position: absolute;
    top: 100px;
    left: 100px;
    box-shadow: 0 0 50px #707070;
}
.divClass:before {
    content: "";
    position: absolute;
    top: -85px;
    left: -85px;
    width: 100px;
    height: 100px;
    background-color: black;
    border-radius: 100%;
}
.divClass:after {
    content: "";
    position: absolute;
    top: -15px;
    left: -14px;
    width: 100px;
    height: 100px;
    background-color: white;
    border-radius: 100%;
}

这里写图片描述

3.画出上面的两个小圆

.left{
    background-color:white;
    width:50px;
    height: 50px;
    position: relative;
    border-radius: 100%;
    top: -65px;
    left: -65px;
}
.right{
    background-color:black;
    width:50px;
    height: 50px;
    position: relative;
    border-radius: 100%;
    top: -40px;
    left: 15px;
    z-index: 1;    /*若是不设置的话,父元素的after会覆盖这部分内容*/
}

这里写图片描述

4.整体加上动画,让旋转起来。

.divClass {
border: 100px solid ;
    border-color: white white black black;      
    width: 0;
    height: 0;
    border-radius: 100%;
    position: absolute;
    top: 100px;
    left: 100px;
    transform-origin: 50% 50%;       /*设置以中心为原点进行旋转*/
    animation: run 2.5s linear infinite;    /*执行动画run,每次执行时间为2.5s ,从开头到结尾以相同的速度来播放动画,重复播放*/
    box-shadow: 0 0 50px #707070;
}
@keyframes run{         /*定义动画run的具体动作*/
    from{
        transform: rotate(0deg);
    }
    /*50%{
        transform: rotate(180deg);
    }*/
    to{
        transform: rotate(360deg);
    }
}

完整代码如下:

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            body {
                margin: 0;
                padding: 0;
            }

            .divClass {
                border: 100px solid ;
                border-color: white white black black;      
                width: 0;
                height: 0;
                border-radius: 100%;
                position: absolute;
                top: 100px;
                left: 100px;
                transform-origin: 50% 50%;       /*设置以中心为原点进行旋转*/
                animation: run 2.5s linear infinite;    /*执行动画run,每次执行时间为2.5s ,从开头到结尾以相同的速度来播放动画,重复播放*/
                box-shadow: 0 0 50px #707070;
            }
            @keyframes run{
                from{
                    transform: rotate(0deg);
                }
                /*50%{
                    transform: rotate(180deg);
                }*/
                to{
                    transform: rotate(360deg);
                }
            }

            .divClass:before {
                content: "";
                position: absolute;
                top: -85px;
                left: -85px;
                width: 100px;
                height: 100px;
                background-color: black;
                border-radius: 100%;
            }
            .divClass:after {
                content: "";
                position: absolute;
                top: -15px;
                left: -14px;
                width: 100px;
                height: 100px;
                background-color: white;
                border-radius: 100%;
            }
            .left{
                background-color:white;
                width:50px;
                height: 50px;
                position: relative;
                border-radius: 100%;
                top: -65px;
                left: -65px;
            }
            .right{
                background-color:black;
                width:50px;
                height: 50px;
                position: relative;
                border-radius: 100%;
                top: -40px;
                left: 15px;
                z-index: 1;    /*若是不设置的话,父元素的after会覆盖这部分内容*/
            }
        </style>
    </head>

    <body>
        <div id="" class="divClass">
            <div id="" class="left">
            </div>
            <div id="" class="right">
            </div>
        </div>
    </body>
</html>
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值