前端 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 分钟前
前端性能追踪工具:用户体验的毫秒战争
前端·笔记·ux
_丿丨丨_5 小时前
XSS(跨站脚本攻击)
前端·网络·xss
天天进步20155 小时前
前端安全指南:防御XSS与CSRF攻击
前端·安全·xss
拾光拾趣录8 小时前
括号生成算法
前端·算法
拾光拾趣录8 小时前
requestIdleCallback:让你的网页如丝般顺滑
前端·性能优化
前端 贾公子8 小时前
vue-cli 模式下安装 uni-ui
前端·javascript·windows
拾光拾趣录9 小时前
链表合并:双指针与递归
前端·javascript·算法
@大迁世界9 小时前
前端:优秀架构的坟墓
前端·架构
期待のcode9 小时前
图片上传实现
java·前端·javascript·数据库·servlet·交互
hbrown10 小时前
Flask+LayUI开发手记(十一):选项集合的数据库扩展类
前端·数据库·python·layui