旋转的太极

CSS+html制作旋转的太极

一、制作太极

1.css画出太极

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旋转的太极</title>
    <style type="text/css">
        .taiji {
            width: 0px;
            height: 400px;
            border-left: 200px #eee solid;
            border-right: 200px #000 solid;
            /* 圆角 */
            border-radius: 50%;
        }
        
        .xby {
            /* 小白圆 */
            width: 20px;
            height: 20px;
            background: #000;
            border: 90px #eee solid;
            border-radius: 50%;
            /* 向左挪100px */
            margin-left: -100px;
        }
        
        .xhy {
            /* 小黑圆 */
            width: 20px;
            height: 20px;
            background: #eee;
            border: 90px #000 solid;
            border-radius: 50%;
            /* 向左挪100px */
            margin-left: -100px;
        }
    </style>
</head>

<body>
    <div class="taiji">
        <div class="xby"></div>
        <div class="xhy"></div>
    </div>
</body>

</html>

2.利用伪元素画太极

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>伪元素制作太极</title>
    <style type="text/css">
        .taiji {
            width: 0px;
            height: 400px;
            border-left: 200px #eee solid;
            border-right: 200px #000 solid;
            border-radius: 50%;
            position: relative;
        }
        
        .taiji:before {
            content: "";
            width: 20px;
            height: 20px;
            background: #000;
            border: 90px #eee solid;
            border-radius: 50%;
            position: absolute;
            margin-left: -100px;
        }
        
        .taiji:after {
            content: "";
            width: 20px;
            height: 20px;
            background: #eee;
            border: 90px #000 solid;
            border-radius: 50%;
            position: absolute;
            margin-top: 200px;
            margin-left: -100px;
        }
    </style>
</head>

<body>
    <div class="taiji">
    </div>
</body>

</html>

二、让太极旋转

添加动画animation和@keyframes设置旋转
以第一种为例

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旋转的太极</title>
    <style type="text/css">
        .taiji {
            /* 动画:动画名称、动画持续时间、动画速度:匀速、执行次数:无数次 */
            animation: tjxz 5s linear infinite;
            width: 0px;
            height: 400px;
            border-left: 200px #eee solid;
            border-right: 200px #000 solid;
            /* 圆角 */
            border-radius: 50%;
        }
        
        .xby {
            /* 小白圆 */
            width: 20px;
            height: 20px;
            background: #000;
            border: 90px #eee solid;
            border-radius: 50%;
            /* 向左挪100px */
            margin-left: -100px;
        }
        
        .xhy {
            /* 小黑圆 */
            width: 20px;
            height: 20px;
            background: #eee;
            border: 90px #000 solid;
            border-radius: 50%;
            /* 向左挪100px */
            margin-left: -100px;
        }
        /* 动画 */
        
        @keyframes tjxz {
            /* 太极旋转从0度到359度 */
            from {
                transform: rotate(0deg);
            }
            /* 因为第360度就是0度,所以只要到359度 */
            to {
                transform: rotate(359deg);
            }
        }
    </style>
</head>

<body>
    <div class="taiji">
        <div class="xby"></div>
        <div class="xhy"></div>
    </div>
</body>

</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值