Css学习: 用 css 画一个带圈的 close

一次 css 实践
更新于: 2023-09-07 17:13:17

效果

Document

重点

  • transform: translate(-50%, -50%) rotate(90deg); 右到左执行
  • 本质是 matrix 变换,不遵循交换原则(3阶矩阵,略,没学过)
Marix
a b c
d e f
0 0 1

代码

<!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>
      .close-circle {
        position: relative;
        width: 80px;
        height: 80px;
        border-radius: 1000px;
        outline: 5px solid #000;
        transform: rotate(45deg);
      }
      .close-circle::before,
      .close-circle::after {
        position: absolute;
        display: block;
        content: "";
        width: 5px;
        height: 70px;
        background: #000;
      }
      .close-circle::before {
        background: red;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
      }
      .close-circle::after {
        background: blue;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%) rotate(90deg);
      }
    </style>
  </head>
  <body>
    <div class="close-circle"></div>
  </body>
</html>