CSS 之 太极图

总体思路: 太极有三个元素, 大圆,两个小圆.html

  1. 有三个内容为空的border矩形
    1. 一大: 默认内容为空, 就只剩下白色背景, 而后右边加一个同样大的黑色border
    2. 二小: 一上一下放在大圆的上下两个鱼眼处
      1. 默认内容为空, 白色背景是中间的小圆, 背景是黑色
      2. 默认内容为空, 黑色背景是中间的小圆, 背景是白色
  2. 太极是圆的啊, 因此把矩形变成圆形的神奇属性:border-radius.
  3. 设置三个圆的相对位置, 半径大小加起来要要严丝合缝.

代码内容:bash

  1. HTML: 一个div
  2. CSS: 包含三个内容,对应三个圆
    1. 每行代码都有注释..
    2. 看不懂快戳评论告诉我!

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    body {
      background-color:grey;
    }
    .yinyang {
      width: 120px; height: 240px;
      background-color: white;
      border-color: black;
      border-style: solid;
      border-width: 1px 121px 1px 1px;
      border-radius: 50%;
      position: relative;
    }
    
    .yinyang:before {
      content: "";
      position: absolute;
      top: 50%;
      left: 50%;
      background-color: white;
      border: 40px solid black;
      border-radius: 50%;
      width: 40px;
      height: 40px;
    }
    
    .yinyang:after {
      content: "";
      position: absolute;
      top: 0;
      left: 50%;
      background-color: black;
      border: 40px solid white;
      border-radius:50%;
      width: 40px;
      height: 40px;
    }
  </style>
</head>
<body>
  <div class="yinyang"></div>
</body>
</html>
复制代码
相关文章
相关标签/搜索