chrome弧形标签页实现思路收录
1. 直线圆角,通过单个伪元素的border-radius产生弧形
<template> <div class="tab-list"> <div v-for="tab in tabs" :key="tab.id" class="tab-item" :class="activeTab === tab.id ? 'active' : ''" @click="onTab(tab.id)" > <div>{{ tab.label }}</div> </div> </div> </template> <script> export default { data() { return { tabs: [ { id: 0, label: '' }, { id: 1, label: '我的信息' }, { id: 2, label: '我信' }, { id: 3, label: '我的信' }, { id: 4, label: '我的信息流' }, { id: 5, label: '' }, ], activeTab: 2, }; }, methods: { onTab(id) { this.activeTab = id; }, }, }; </script> <style lang="scss"> // scss $tab-height: 52px; $active-color: #ffffff; $default-color: #e2e8f8; $primary-color: blue; .tab-list { display: flex; position: relative; z-index: 2; border-radius: 12px 12px 0 0; background-color: $default-color; overflow: hidden; padding: 0 80px; .tab-item:first-child, .tab-item:last-child { flex: none; } .tab-item:last-child::after{ display: none; } .tab-item { flex: auto; height: $tab-height; display: flex; justify-content: center; align-items: center; font-size: 14px; color: $primary-color; font-weight: 600; position: relative; } .tab-item.active { opacity: 1; background: #fff; border-radius: 12px 12px 0 0; box-shadow: 12px 43px 0 $active-color, -12px 43px 0 0 $active-color; } .tab-item.active::before { content: ''; position: absolute; bottom: 0; width: 12px; height: $tab-height; border-bottom-right-radius: 12px; background: $default-color; left: -12px; z-index: 1; } .tab-item.active::after { content: ''; position: absolute; bottom: 0; width: 12px; height: $tab-height; right: 6px; background: $default-color; border-bottom-left-radius: 12px; z-index: 1; right: -12px; } } </style>
详细可参考 实现tabs圆角及反圆角效果
2. 斜线圆角,通过两个相邻伪元素的border-radius和skew配合产生两个弧形
<template> <div class="tab-list"> <div v-for="tab in tabs" :key="tab.id" class="tab-item" :class="activeTab === tab.id ? 'active' : ''" @click="onTab(tab.id)" > <div>{{ tab.label }}</div> </div> </div> </template> <script> export default { data() { return { tabs: [ { id: 0, label: '' }, { id: 1, label: '我的信息' }, { id: 2, label: '我信' }, { id: 3, label: '我的信' }, { id: 4, label: '我的信息流' }, { id: 5, label: '' }, ], activeTab: 1, }; }, methods: { onTab(id) { this.activeTab = id; }, }, }; </script> <style lang="scss"> // scss $tab-height: 52px; $active-color: #ffffff; $default-color: #e2e8f8; $primary-color: blue; .tab-list { display: flex; position: relative; z-index: 2; border-radius: 12px 12px 0 0; background-color: $default-color; overflow: hidden; padding: 0 80px; .tab-item:first-child, .tab-item:last-child { flex: none; } .tab-item:last-child::after{ display: none; } .tab-item { flex: auto; height: $tab-height; display: flex; justify-content: center; align-items: center; font-size: 14px; color: $primary-color; font-weight: 600; position: relative; } .tab-item.active { opacity: 1; background: #fff; border-radius: 12px 12px 0 0; box-shadow: 24px 40px 0 $active-color, -24px 40px 0 0 $active-color; } .tab-item::before { content: ''; position: absolute; bottom: 0; width: 12px; height: $tab-height; left: 6px; border-bottom-left-radius: 12px; background: $default-color; transform: skewX(15deg); } .tab-item.active::before { left: -6px; border-top-left-radius: 12px; background: $active-color; transform: skewX(-15deg); } .tab-item::after { content: ''; position: absolute; bottom: 0; width: 12px; height: $tab-height; right: 6px; background: $default-color; border-bottom-right-radius: 12px; transform: skewX(-15deg); z-index: 1; } .tab-item.active::after { right: -6px; border-top-right-radius: 12px; background: $active-color; transform: skewX(15deg); } } </style>
详细参考此文 实现tabs圆角及反圆角效果(PLUS)