tab选项卡,反圆角样式

<template>
  <div class="container">
    <div class="tab-list">
      <div
        v-for="tab in tabList"
        :key="tab.id"
        class="tab-item"
        :class="activeTab === tab.id ? 'tab-selected' : ''"
        @click="onTab(tab.id)"
      >
        <div>{{ tab.label }}</div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'

const activeTab = ref('1')
const tabList = ref([
  { id: '1', label: '对话' },
  { id: '2', label: '对话1' },
  { id: '3', label: '对话2' },
  { id: '4', label: '对话1' },
  { id: '5', label: '对话2' },
  { id: '6', label: '对话1' },
  { id: '7', label: '对话2' }
])

const onTab = (id) => {
  activeTab.value = id
}
</script>

<style scoped lang="scss">
$tab-height: 52px;
$primary-color: #fff;
$tab-bgcolor: #243451;

.tab-list {
  width: 80%;
  display: flex;
  position: relative;
  z-index: 2;
  border-radius: 12px 12px 0 0;
  background-color: #121821;
  overflow: hidden; // 新增
}

.tab-list {
  display: flex;
  border-radius: 12px 12px 0 0;
  background-color: $tab-bgcolor;

  .tab-item {
    flex: 1;
    height: $tab-height;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 15px;
    opacity: 0.65;
    color: $primary-color;
    font-weight: 600;
    position: relative;
  }

  .tab-icon {
    width: 17px;
    height: 17px;
    margin-right: 4px;
  }

  .tab-selected {
    opacity: 1;
    background: #121821;
    // 新增
    border-radius: 12px 12px 0 0;
    // 新装置
    // box-shadow: 12px 12px 0 0 blue, -12px 12px 0 0 blue;
    box-shadow:
      12px 12px 0 0 #121821,
      -12px 12px 0 0 #121821;
    border-top: 0.5px solid #859bbf;
    border-bottom: 0.5px solid #121821;
    margin-right: 8px;
    margin-left: -2px;
  }

  .tab-selected::before {
    content: '';
    position: absolute;
    left: -12px;
    bottom: 0;
    width: 12px;
    height: 44px;
    background: #243451; // 修改
    border-radius: 0 0 12px 0;
    border-right: 0.5px solid #859bbf;
  }

  .tab-selected::after {
    content: '';
    position: absolute;
    right: -12px;
    bottom: 0;
    width: 12px;
    height: 44px;
    background: #243451; // 修改
    border-radius: 0 0 0 12px;
    border-left: 0.5px solid #859bbf;
  }
}
</style>

 

  1. 伪元素装饰

    • .tab-selected::before 和 .tab-selected::after 是伪元素,它们在激活标签页的左右两侧各添加了一个装饰性的三角形效果。
    • 这些伪元素通过设置position: absolute;定位在激活标签页的底部左右两侧,通过widthheightbackgroundborder属性形成了三角形的外观。
    • border-radiusborder属性进一步细化了三角形的边缘,使其与整体设计协调。

实际效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值