纯css tab 栏实现中间凸起的效果

在开发h5页面时,常常会遇到设计稿上底部tab栏会是个中间凸起的效果,如下:


image.png

当然我这个比较丑,不要在意。直接贴图片当然是最快的,但是如何纯 css 实现这种效果呢,看代码:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
    />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      .tab-box {
        margin: 100px auto;
        width: 750px;
      }

      .tabBar {
        --tabBg: #e89595;
        display: flex;
        justify-content: space-between;
        align-content: center;
        box-sizing: border-box;
        background-color: var(--tabBg);
        position: relative;
        height: 102px;
        padding-bottom: 10px;
        filter: drop-shadow(0 0 5px #000000) drop-shadow(0 0 5px #000000);
      }
      .tabBar::after {
        content: " ";
        background-color: var(--tabBg);
        width: 130px;
        height: 130px;
        border-radius: 50%;
        clip-path: polygon(0% 0%, 100% 0%, 100% 14%, 0 14%);
        position: absolute;
        left: 50%;
        top: -14%;
        transform: translateX(-50%);
        z-index: 0;
      }
      .tabBar span {
        cursor: pointer;
        z-index: 1;
        position: relative;
        flex: 1;
        text-align: center;
        font-size: 20px;
        color: rgba(0, 0, 0, 0.5);
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        flex-direction: column;
      }
    </style>
  </head>
  <body>
    <div class="wrap">
      <div class="tab-box">
        <div class="tabBar">
          <span>tab页1</span>
          <span>tab页2</span>
          <span>tab页3</span>
        </div>
      </div>
    </div>
  </body>
</html>

其中关键的一点是借助了 filter: drop-shadow(),使用 drop-shadow 可以让我们给一个元素添加阴影,这个阴影并不对应于它的边界框,而是使用该元素的Alpha蒙版,比如给图片添加阴影,文字添加阴影。

image.png

image.png

看到个比较炫酷的demo,感兴趣的可以看看。

来都来了,请点个赞吧!若能打赏不胜感激,谢谢支持!
本文地址:https://www.jianshu.com/p/c452a1bc3437?v=1739968245831,转载请注明出处,谢谢。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容