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

1. 效果图

2. 开始

准备一个元素,将元素左上角,右上角设为圆角。

html 复制代码
<!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>

然后要在左右两边拼接弧形,我们可以写两个伪元素

css 复制代码
.tab::before,
.tab::after {
  content: "";
  position: absolute;
  width: 10px;
  height: 10px;
  bottom: 0;
}

.tab::before {
  left: -10px;
}
.tab::before {
  right: -10px;
}

那怎么将这两个元素做成弧形呢,可以使用渐变。

css 复制代码
.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);
}

这下我们有了弧形,那怎么做成效果图的样式呢,最后我们可以使用旋转。

css 复制代码
.tab {
  transform: perspective(30px) rotateX(20deg);
  transform-origin: center bottom;
}

3.完整代码

html 复制代码
<!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>
相关推荐
一颗宁檬不酸6 分钟前
页面布局练习
前端·html·页面布局
金木讲编程1 小时前
Claude、Agent与Copilot协作生成Angular应用
前端·ai编程
振华OPPO2 小时前
Vue:“onMounted“ is defined but never used no-unused-vars
前端·javascript·css·vue.js·前端框架
欧雷殿2 小时前
在富阳银湖成立地域化的软件研发团队
前端·程序员·创业
狂炫冰美式3 小时前
前端实时推送 & WebSocket 面试题(2026版)
前端·http·面试
JefferyXZF3 小时前
新手建站零门槛!Vercel+Cloudflare+Namesilo域名购买部署全流程
前端
yinuo3 小时前
微信浏览器缓存机制大揭秘:为什么你总刷不出新页面?
前端
拉不动的猪3 小时前
try...catch 核心与生态协作全解析
前端·javascript·vue.js
Xeon_CC4 小时前
在react-app-rewired工程项目中,调试AntVG6库源码包。
前端·react.js·前端框架
o***Z4484 小时前
前端无障碍开发检查清单,WCAG合规
前端