CSS实现旋转的太极图效果

太极的组成

两个黑白半圆拼接成一个大圆,大圆中有两个小的黑白半圆和两个更小的圆
具体图形如图所示

定义一个大框框w用来装太极,
定义两个矩形re(将其变为两个半圆)
定义两个小的矩形c(将其变为两个小的半圆)
定义两个小圆a
在这里插入图片描述

整体代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            background-color: #cccccc;   /*给body整体一个灰色背景*/
            overflow: hidden; 
        }
  
    .w{       /*装太极的盒子*/
      width: 500px;
      height: 500px;
      position: relative;           /*给父级一个相对定位。子级用绝对定位*/
      margin: 100px auto;             /* 让这个盒子水平居中,上下间距为100px */
      /*调用动画*/
      /* animation: circle 2s linear infinite forwards;   */
    }
    .re1{      /* 矩形1 即太极的左半边 */
        width: 200px;
        height: 400px;
        background-color: black;
        border-radius: 200px 0px 0px 200px;       /* 半圆*/
        position: absolute;
        left: 50px;
        bottom: 50px;

    }
    .re2{        /*矩形2 即太极的右半边*/
        width: 200px;
        height: 400px;
        background-color:white;
        border-radius: 0px 200px 200px 0px;
        position: absolute;
        left: 250px;
        bottom: 50px;

    }
    .c1{    /*小的半圆黑色部分*/
        width: 100px;
        height: 200px;
        background-color: black;
        border-radius: 0px 100px 100px 0px;
        position: absolute;
        left: 0px;
        bottom: 0px;
    }
    .c2{      /*小的半圆白色部分*/
        width: 100px;
        height: 200px;
        background-color: white;
        border-radius: 100px 0px 0px 100px;
        position: absolute;
        left: 100px;
        bottom: 200px;
    }
    .a1{        /*小圆白色部分*/
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color:white ;
        position:absolute;
        left: -15px;
        bottom: 75px;
    }
    .a2{    /*小圆黑色部分*/
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color:black ;
        position:absolute;
        right: -25px;
        bottom: 75px;
        z-index :1;
    }
    @keyframes circle{      /*创建动画*/
        0%{
            transform: rotate(0deg);
        }
        100%{
            transform: rotate(360deg);
        }
    }
</style>
</head>
<body>
    <!-- 定义一个大框框w用来装太极,
        定义两个矩形re(将其变为两个半圆),定义两个小的矩形c(将其变为两个小的半圆)
        定义两个小圆a 
    -->
   
    <div class="w">
        <div class="re1">
        <div class="c2">
            <div class="a2"></div>
        </div>
        </div>
        <div class="re2">
        <div class="c1">
        <div class="a1">
            </div>
        </div>
        </div>  
    </div>
    
</body>
</html>

主要用到的有

关键帧动画
调用动画
绝对定位相对定位
圆角属性

猜你喜欢

转载自blog.csdn.net/weixin_48291770/article/details/107518062
今日推荐