vue3 使用css实现一个弧形选中角标样式

文章目录

  • [1. 实现效果](#1. 实现效果)
  • [2. 实现demo](#2. 实现demo)

在前端开发中,ui同学经常会设计这样的样式,用于区分选中的状态

下面抽空简单些了一下,记录下,后面直接复制用

1. 实现效果

  1. 实现一个菜单切换,右下角有个角标的样式

2. 实现demo

  1. 主要是通过 伪类 和 线性渐变 属性实现
html 复制代码
<script setup lang="ts">
	let index = ref(1);
	let tabsList = ref([
		{ tabName: "登录", key: 1 },
		{ tabName: "注册", key: 2 }
	]);
	const openTab = (key: number) => {
		index.value = key;
	};
</script>

<template>
	<div class="tabs">
		<span :class="['tab', item.key == index && 'active']" @click="openTab(item.key)" v-for="item in tabsList"
			:key="item.key">
			{{ item.tabName }}
		</span>
	</div>
</template>

<style lang="less" scoped>
.tabs {
	margin-top: 50px;
	display: flex;
	justify-content: center;
	align-items: center;

	.tab {
		display: flex;
		align-items: center;
		justify-content: center;
		color: #fff;
		width: 150px;
		height: 40px;
		border-radius: 10px 10px 0 0;
		position: relative;
		background: #ccc;

		&.active {
			background: #e74d5c;

			&::after {
				content: "";
				position: absolute;
				width: 15px;
				height: 15px;
				bottom: 0;
				z-index: 1;
			}
		}

		&:first-child {
			&::after {
				right: -15px;
				background: radial-gradient(circle at 15px 0, transparent 15px, #e74d5c 15px);
			}
		}

		&:last-child {
			&::after {
				left: -15px;
				background: radial-gradient(circle at 0px 0, transparent 15px, #e74d5c 15px);
			}
		}
	}
}
</style>
相关推荐
空中湖10 分钟前
用 React 写数据大屏:为什么我不建议用图表库
前端·react.js·前端框架
狮子座的男孩2 小时前
html+css基础:25、3D变换(3D空间与景深/透视点的位置/位移/旋转/缩放/多重变换/背部可见性)
css·经验分享·html·旋转·透视点·缩放/位移·3d变换/空间与景深
欣欣之王来了2 小时前
原始HTML插值:v-html指令的使用与安全风险
前端·学习·架构·项目·vue3教程
IT_陈寒2 小时前
Redis的LRU淘汰策略坑了我一整天
前端·人工智能·后端
计算机魔术师2 小时前
砍半价格、参数再涨,国产旗舰追到 Opus 鼻尖了
前端
特立独行的猫A2 小时前
10 MB 的桌面 AI 客户端:用仓颉 + 系统 WebView 替代 Electron
前端·harmonyos
修炼的dance3 小时前
白底图存JPG,sharp开mozjpeg背景杂点少近三成
前端
anOnion3 小时前
构建无障碍组件之Grid Pattern
前端·html·交互设计
乔旭伟4 小时前
Vben3 中后台表格封装实战:useVbenVxeGrid 的全局收敛与七个坑
前端·anti-design-vue·1024程序员节
鶴哥只手遮天4 小时前
jQuery 4.0 源码架构与工程实践-第 10 章 尺寸、几何与显隐
前端·javascript·jquery