css 标签效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tab Component</title>
<style>
body {
margin: 0;
padding: 20px;
background: #e5e5e5;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.tabs {
margin-top: 10px;
background: #ffffff;
display: flex;
justify-content: space-between;
}
.tabs-item {
width: 50%;
position: relative;
}
.tabs-btn {
cursor: pointer;
width: 100%;
display: inline-block;
background-color: #ffffff;
text-align: center;
transition: 0.25s ease;
border: none;
height: 100px;
font-size: 34px;
font-weight: 500;
color: #3d3d40;
line-height: 44px;
border-radius: 0;
position: relative;
}
.active-left {
background-color: red;
outline: none;
border-radius: 30px 30px 0 0;
}
.active-left::after {
content: '';
position: absolute;
top: 0;
right: -96px;
height: 100px;
width: 100px;
background: radial-gradient(circle at 0 0, transparent 100px, red 100px);
z-index: 10;
border-radius: 0 26px 0 0;
transform-origin: center;
transform: rotateY(180deg);
}
.active-right {
border-radius: 30px 30px 0 0;
background-color: #33e706;
outline: none;
}
.active-right::after {
content: '';
position: absolute;
top: 0;
left: -96px;
height: 100px;
width: 100px;
background: radial-gradient(circle at 0 0, transparent 100px, #33e706 100px);
border-radius: 0 20px 0 0;
}
.tabs-content {
background: #f4f5f9;
padding: 20px;
min-height: 200px;
}
</style>
</head>
<body>
<div class="tabs">
<div class="tabs-item">
<button class="tabs-btn active-left">Tab 0</button>
<div class="tabs-content"></div>
</div>
<div class="tabs-item">
<button class="tabs-btn">Tab 1</button>
<div class="tabs-content"></div>
</div>
</div>
<script>
// 如果需要切换标签,可以添加点击事件
const tabs = document.querySelectorAll('.tabs-btn');
tabs.forEach((tab, index) => {
tab.addEventListener('click', () => {
// 移除所有激活状态
tabs.forEach(t => {
t.classList.remove('active-left', 'active-right');
});
// 根据位置添加对应的激活类
if (index === 0) {
tab.classList.add('active-left');
} else {
tab.classList.add('active-right');
}
});
});
</script>
</body>
</html>
Tab Component

浙公网安备 33010602011771号