CSS3 border 边框的形状

133 阅读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>
    .box {
      width: 30px;
      height: 30px;

      border: 100px solid red;
      border-right-color: blue;
      border-top-color: yellow;
      border-bottom-color: pink;
    }
    .box1 {
      margin-top: 10px;
      width: 100px;
      height: 100px;
      border: 50px solid red;
      border-right: none;

      /* 当圆角幅度太大时,则会出现扭曲角度 */
      border-bottom-right-radius: 100px;
    }
  </style>
</head>
<body>
  <div class="box"></div>
  <div class="box1"></div>
</body>
</html>
  • demo 效果


  • 爱心效果
<!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>
    .heart {
      width: 200px;
      height: 300px;
      margin: 100px auto;
      position: relative;
    }

    .heart::before, .heart::after {
      content: "dzm";
      width: 100%;
      height: 100%;
      position: absolute;
      background-color: red;
      left: 0;
      top: 0;
      border-radius: 100px 100px 0 0;
      transform: rotate(-45deg);
      text-align: center;
      line-height: 100px;
      color: yellow;
      font-size: 30px;
    }

    .heart::after {
      content: "xyq";
      left: 71px;
      transform: rotate(45deg);
    }
  </style>
</head>
<body>
  <div class="heart">

  </div>
</body>
</html>
  • 心形效果