前端 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>
相关推荐
孤水寒月2 小时前
基于HTML的悬窗可拖动记事本
前端·css·html
祝余呀2 小时前
html初学者第一天
前端·html
耶啵奶膘4 小时前
uniapp+firstUI——上传视频组件fui-upload-video
前端·javascript·uni-app
视频砖家5 小时前
移动端Html5播放器按钮变小的问题解决方法
前端·javascript·viewport功能
lyj1689975 小时前
vue-i18n+vscode+vue 多语言使用
前端·vue.js·vscode
小白变怪兽7 小时前
一、react18+项目初始化(vite)
前端·react.js
ai小鬼头7 小时前
AIStarter如何快速部署Stable Diffusion?**新手也能轻松上手的AI绘图
前端·后端·github
墨菲安全8 小时前
NPM组件 betsson 等窃取主机敏感信息
前端·npm·node.js·软件供应链安全·主机信息窃取·npm组件投毒
GISer_Jing8 小时前
Monorepo+Pnpm+Turborepo
前端·javascript·ecmascript
天涯学馆8 小时前
前端开发也能用 WebAssembly?这些场景超实用!
前端·javascript·面试