<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue3风格汉堡包菜单 | 纯CSS实现</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
color: #fff;
}
.vue-container {
width: 100%;
max-width: 1200px;
background: rgba(255, 255, 255, 0.95);
border-radius: 20px;
box-shadow: 0 15px 50px rgba(0, 0, 0, 0.3);
overflow: hidden;
position: relative;
}
.vue-header {
background: linear-gradient(90deg, #42b883 0%, #35495e 100%);
padding: 30px 40px;
text-align: center;
position: relative;
overflow: hidden;
}
.vue-header::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path fill="rgba(255,255,255,0.1)" d="M30,30 Q50,10 70,30 T90,50 Q70,70 50,90 T10,50 Q30,30 50,10 Z"/></svg>');
background-size: 200px;
opacity: 0.2;
}
.vue-logo {
width: 80px;
height: 80px;
margin: 0 auto 20px;
position: relative;
}
.vue-logo .circle {
position: absolute;
border-radius: 50%;
border: 3px solid #42b883;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
color: #42b883;
font-size: 40px;
font-weight: bold;
background: white;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}
h1 {
font-size: 2.8rem;
margin-bottom: 10px;
text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
max-width: 700px;
margin: 0 auto;
line-height: 1.6;
}
.content {
display: flex;
flex-wrap: wrap;
padding: 40px;
color: #2c3e50;
}
.demo-section {
flex: 1;
min-width: 300px;
padding: 30px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
border-right: 1px solid #eee;
}
.info-section {
flex: 1;
min-width: 300px;
padding: 30px;
}
/* Vue3汉堡包菜单核心样式 */
.vue-hamburger {
display: flex;
flex-direction: column;
align-items: center;
gap: 40px;
width: 100%;
}
.menu-toggle {
display: none;
}
.hamburger-btn {
width: 80px;
height: 80px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
cursor: pointer;
position: relative;
transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
background: #42b883;
border-radius: 50%;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
z-index: 100;
}
.hamburger-btn span {
display: block;
width: 45px;
height: 5px;
background: white;
border-radius: 3px;
position: absolute;
transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
transform-origin: center;
}
/* 默认状态 - 三条横线 */
.hamburger-btn span:nth-child(1) {
top: 22px;
}
.hamburger-btn span:nth-child(2) {
top: 37px;
}
.hamburger-btn span:nth-child(3) {
top: 52px;
}
/* 悬停状态 */
.hamburger-btn:hover {
background: #359f70;
transform: scale(1.05);
}
.hamburger-btn:hover span {
background: #fff;
}
/* 菜单打开状态(复选框选中) */
.menu-toggle:checked + .hamburger-btn span:nth-child(1) {
transform: translateY(15px) rotate(45deg);
top: 37px;
}
.menu-toggle:checked + .hamburger-btn span:nth-child(2) {
opacity: 0;
transform: scale(0);
}
.menu-toggle:checked + .hamburger-btn span:nth-child(3) {
transform: translateY(-15px) rotate(-45deg);
top: 37px;
}
.menu-toggle:checked + .hamburger-btn {
background: #35495e;
}
/* 焦点状态 */
.hamburger-btn:focus {
outline: 3px solid rgba(66, 184, 131, 0.5);
outline-offset: 3px;
}
/* 禁用状态 */
.menu-toggle:disabled + .hamburger-btn {
background: #95a5a6;
cursor: not-allowed;
box-shadow: none;
}
.menu-toggle:disabled + .hamburger-btn span {
background: #ecf0f1;
}
/* 导航菜单 */
.nav-menu {
width: 100%;
max-width: 300px;
background: white;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
overflow: hidden;
transform: scale(0.95);
opacity: 0;
transform-origin: top center;
transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
max-height: 0;
}
.menu-toggle:checked ~ .nav-menu {
opacity: 1;
transform: scale(1);
max-height: 500px;
}
.nav-menu ul {
list-style: none;
padding: 20px 0;
}
.nav-menu li {
padding: 15px 30px;
display: flex;
align-items: center;
transition: all 0.3s;
cursor: pointer;
}
.nav-menu li i {
width: 30px;
font-size: 18px;
color: #42b883;
}
.nav-menu li span {
font-weight: 500;
}
.nav-menu li:hover {
background: #f5faf8;
}
.nav-menu li:hover span {
color: #42b883;
}
.nav-menu li.active {
background: #e9f5f1;
border-left: 4px solid #42b883;
}
.nav-menu li.active span {
color: #42b883;
font-weight: 600;
}
.section-title {
font-size: 1.8rem;
color: #2c3e50;
margin-bottom: 25px;
padding-bottom: 15px;
border-bottom: 2px solid #42b883;
display: flex;
align-items: center;
gap: 10px;
}
.section-title i {
color: #42b883;
}
.vue-features {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-top: 30px;
}
.feature-card {
background: #f8faf9;
border-radius: 12px;
padding: 25px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
transition: all 0.3s;
border-left: 4px solid #42b883;
}
.feature-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}
.feature-card h3 {
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 15px;
color: #35495e;
}
.feature-card i {
width: 30px;
height: 30px;
background: #42b883;
color: white;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
.feature-card p {
line-height: 1.7;
color: #4a6572;
}
.state-controls {
display: flex;
flex-wrap: wrap;
gap: 15px;
margin-top: 40px;
justify-content: center;
}
.state-btn {
padding: 12px 25px;
border: none;
border-radius: 8px;
font-weight: bold;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
display: flex;
align-items: center;
gap: 8px;
}
.state-btn:hover {
transform: translateY(-3px);
box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}
.state-btn:active {
transform: translateY(1px);
}
.btn-default {
background: #42b883;
color: white;
}
.btn-hover {
background: #3498db;
color: white;
}
.btn-active {
background: #35495e;
color: white;
}
.btn-focus {
background: #5bc0a6;
color: white;
}
.btn-disabled {
background: #95a5a6;
color: white;
}
.code-block {
background: #2c3e50;
color: #ecf0f1;
padding: 25px;
border-radius: 10px;
font-family: 'Fira Code', monospace;
margin-top: 30px;
overflow-x: auto;
font-size: 0.95rem;
line-height: 1.6;
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
color: #42b883;
font-weight: bold;
}
@media (max-width: 768px) {
.demo-section {
border-right: none;
border-bottom: 1px solid #eee;
padding-bottom: 40px;
}
.info-section {
padding-top: 40px;
}
.content {
padding: 20px;
}
h1 {
font-size: 2.2rem;
}
}
footer {
text-align: center;
padding: 25px;
background: #35495e;
color: rgba(255, 255, 255, 0.8);
font-size: 1rem;
}
.vue-watermark {
position: absolute;
top: 20px;
right: 20px;
font-size: 14px;
font-weight: bold;
color: #42b883;
background: rgba(255, 255, 255, 0.9);
padding: 5px 15px;
border-radius: 20px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
</style>
</head>
<body>
<div class="vue-container">
<div class="vue-watermark">Vue3 CSS Component</div>
<div class="vue-header">
<div class="vue-logo">
<div class="circle">V</div>
</div>
<h1>Vue3 汉堡包菜单</h1>
<p class="subtitle">纯CSS实现的响应式导航菜单组件,具有平滑过渡动画和完整交互状态</p>
</div>
<div class="content">
<div class="demo-section">
<h2 class="section-title"><i class="fas fa-laptop-code"></i> 组件演示</h2>
<div class="vue-hamburger">
<!-- 隐藏的复选框控制菜单状态 -->
<input type="checkbox" id="menuToggle" class="menu-toggle">
<!-- 汉堡包按钮 -->
<label for="menuToggle" class="hamburger-btn">
<span></span>
<span></span>
<span></span>
</label>
<!-- 导航菜单 -->
<div class="nav-menu">
<ul>
<li class="active">
<i class="fas fa-home"></i>
<span>首页</span>
</li>
<li>
<i class="fas fa-user"></i>
<span>个人资料</span>
</li>
<li>
<i class="fas fa-cog"></i>
<span>设置</span>
</li>
<li>
<i class="fas fa-chart-bar"></i>
<span>数据统计</span>
</li>
<li>
<i class="fas fa-envelope"></i>
<span>消息通知</span>
</li>
<li>
<i class="fas fa-sign-out-alt"></i>
<span>退出登录</span>
</li>
</ul>
</div>
</div>
<div class="state-controls">
<button class="state-btn btn-default" onclick="resetMenu()">
<i class="fas fa-sync-alt"></i> 重置状态
</button>
</div>
</div>
<div class="info-section">
<h2 class="section-title"><i class="fas fa-info-circle"></i> 功能特性</h2>
<div class="vue-features">
<div class="feature-card">
<h3><i class="fas fa-magic"></i> 纯CSS实现</h3>
<p>使用CSS伪类和兄弟选择器实现状态切换,无需任何JavaScript代码</p>
</div>
<div class="feature-card">
<h3><i class="fas fa-bolt"></i> 平滑动画</h3>
<p>使用cubic-bezier缓动函数实现流畅的变形动画,提供优雅的用户体验</p>
</div>
<div class="feature-card">
<h3><i class="fas fa-mobile-alt"></i> 响应式设计</h3>
<p>完美适配各种屏幕尺寸,在移动设备和桌面设备上均有出色表现</p>
</div>
<div class="feature-card">
<h3><i class="fas fa-palette"></i> Vue3主题</h3>
<p>采用Vue3官方配色方案(#42b883和#35495e),完美融入Vue应用</p>
</div>
</div>
<h2 class="section-title" style="margin-top: 40px;"><i class="fas fa-code"></i> 核心实现</h2>
<div class="code-block">
<div class="code-header">
<div>hamburger-menu.css</div>
<div>Vue3 CSS Component</div>
</div>
/* 汉堡包按钮容器 */
.hamburger-btn {
width: 80px;
height: 80px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
cursor: pointer;
position: relative;
transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
background: #42b883;
border-radius: 50%;
}
/* 三条横线 */
.hamburger-btn span {
display: block;
width: 45px;
height: 5px;
background: white;
position: absolute;
transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
transform-origin: center;
}
/* 默认状态位置 */
.hamburger-btn span:nth-child(1) { top: 22px; }
.hamburger-btn span:nth-child(2) { top: 37px; }
.hamburger-btn span:nth-child(3) { top: 52px; }
/* 选中状态(菜单打开) */
.menu-toggle:checked + .hamburger-btn span:nth-child(1) {
transform: translateY(15px) rotate(45deg);
top: 37px;
}
.menu-toggle:checked + .hamburger-btn span:nth-child(2) {
opacity: 0;
transform: scale(0);
}
.menu-toggle:checked + .hamburger-btn span:nth-child(3) {
transform: translateY(-15px) rotate(-45deg);
top: 37px;
}
/* 导航菜单动画 */
.nav-menu {
transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
opacity: 0;
transform: scale(0.95);
max-height: 0;
}
.menu-toggle:checked ~ .nav-menu {
opacity: 1;
transform: scale(1);
max-height: 500px;
}
</div>
</div>
</div>
<footer>
<p>Vue3 汉堡包菜单组件 | 纯CSS实现 | 无JavaScript依赖 | 响应式设计</p>
</footer>
</div>
<script>
// 简单重置函数
function resetMenu() {
document.getElementById('menuToggle').checked = false;
}
// 添加Vue3水印效果
document.addEventListener('DOMContentLoaded', () => {
const watermark = document.querySelector('.vue-watermark');
let angle = 0;
setInterval(() => {
angle = (angle + 0.5) % 360;
watermark.style.textShadow = `
0 0 5px rgba(66, 184, 131, 0.7),
${Math.sin(angle * Math.PI/180) * 3}px ${Math.cos(angle * Math.PI/180) * 3}px 8px rgba(66, 184, 131, 0.4)
`;
}, 50);
});
</script>
</body>
</html>