涛声依旧在 发表于 2024-9-18 03:50:04

前端 CSS 经典:弧形边框选项卡

1. 效果图

https://i-blog.csdnimg.cn/blog_migrate/5bfc4f8681a6cda792d16724d29c50ea.jpeg
2. 开始

准备一个元素,将元素左上角,右上角设为圆角。
<!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>
      .tab {
      width: 150px;
      height: 40px;
      margin: 0 auto;
      background: #ed6a5e;
      border-radius: 10px 10px 0 0;
      }
    </style>
</head>
<body>
    <div class="tab"></div>
</body>
</html> https://i-blog.csdnimg.cn/blog_migrate/27e5988a1998adcbcf55d700c0ab49aa.jpeg
然后要在左右双方拼接弧形,我们可以写两个伪元素
.tab::before,
.tab::after {
content: "";
position: absolute;
width: 10px;
height: 10px;
bottom: 0;
}

.tab::before {
left: -10px;
}
.tab::before {
right: -10px;
} https://i-blog.csdnimg.cn/blog_migrate/7f286c013e651e308ea70cb0d6c6c357.jpeg
那怎么将这两个元素做成弧形呢,可以使用渐变。
.tab::before {
background: radial-gradient(circle at 0 0, transparent 10px, #ed6a5e 10px);
}
.tab::after {
background: radial-gradient(circle at 100% 0, transparent 10px, #ed6a5e 10px);
} https://i-blog.csdnimg.cn/blog_migrate/d2e5bdc2d9655c375aedcf83a4c393eb.jpeg
这下我们有了弧形,那怎么做成效果图的样式呢,末了我们可以使用旋转。
.tab {
transform: perspective(30px) rotateX(20deg);
transform-origin: center bottom;
}
https://i-blog.csdnimg.cn/blog_migrate/2260d403f6f9aa22dae19913f974beee.jpeg 
3.完备代码

<!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>
      .tab {
      width: 150px;
      height: 40px;
      margin: 0 auto;
      background: #ed6a5e;
      border-radius: 10px 10px 0 0;
      position: relative;
      transform: perspective(30px) rotateX(20deg);
      transform-origin: center bottom;
      }
      .tab::before,
      .tab::after {
      content: "";
      position: absolute;
      width: 10px;
      height: 10px;
      bottom: 0;
      background: #000;
      }

      .tab::before {
      left: -10px;
      background: radial-gradient(
          circle at 0 0,
          transparent 10px,
          #ed6a5e 10px
      );
      }
      .tab::after {
      right: -10px;
      background: radial-gradient(
          circle at 100% 0,
          transparent 10px,
          #ed6a5e 10px
      );
      }
    </style>
</head>
<body>
    <div class="tab"></div>
</body>
</html>


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 前端 CSS 经典:弧形边框选项卡