
页面基础结构:使用 HTML5 标准结构,设置了中文编码和移动端适配
样式部分:
背景使用渐变粉色系,营造温馨的生日氛围
卡片采用半透明白色背景 + 阴影,有浮动动画效果
响应式设计,适配手机和电脑端
动态效果:
页面加载后会生成随机飘落的生日装饰元素(气球、彩带、糖果等)
卡片有轻微的上下浮动动画,增加灵动感
可自定义内容:
你可以修改 <h1> 标签里的标题(比如加上对方的名字:生日快乐,小明!)
修改 <p> 标签里的祝福语,换成你想对对方说的话
替换 .cake 里的图标(比如换成🎁、🥳等)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>生日快乐!🎂</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: "Microsoft YaHei", "PingFang SC", sans-serif; background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%); height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; overflow: hidden; color: #333; } /* 生日卡片样式 */ .birthday-card { background: rgba(255, 255, 255, 0.95); padding: 40px 60px; border-radius: 20px; box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1); text-align: center; z-index: 10; animation: float 3s ease-in-out infinite; } /* 浮动动画 */ @keyframes float { 0% { transform: translateY(0px); } 50% { transform: translateY(-10px); } 100% { transform: translateY(0px); } } .birthday-card h1 { font-size: 3rem; color: #e91e63; margin-bottom: 20px; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1); } .birthday-card p { font-size: 1.5rem; line-height: 1.8; margin-bottom: 30px; color: #666; } .birthday-card .wish { font-size: 1.2rem; color: #ff5722; font-weight: bold; } /* 蛋糕图标 */ .cake { font-size: 5rem; margin: 20px 0; } /* 雪花样式 */ .snowflake { position: absolute; color: #fff; font-size: 1.5rem; opacity: 0.8; animation: fall linear infinite; } @keyframes fall { 0% { transform: translateY(-10px) rotate(0deg); opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { transform: translateY(100vh) rotate(360deg); opacity: 0; } } /* 响应式适配 */ @media (max-width: 768px) { .birthday-card { padding: 30px 40px; margin: 0 20px; } .birthday-card h1 { font-size: 2rem; } .birthday-card p { font-size: 1.2rem; } } </style> </head> <body> <!-- 生日卡片 --> <div> <div>🎂</div> <h1>生日快乐!</h1> <p>愿你的每一天都像今天一样快乐</p> <p>健康、平安、顺遂,所有美好都如约而至~</p> </div> <script> // 生成雪花效果 function createSnowflakes() { const snowflakes = "🎈🎀✨🍬🍭🎉🎊"; // 生日装饰元素 const numberOfSnowflakes = 50; for (let i = 0; i < numberOfSnowflakes; i++) { const snowflake = document.createElement("div"); snowflake.classList.add("snowflake"); // 随机选择装饰元素 snowflake.textContent = snowflakes[Math.floor(Math.random() * snowflakes.length)]; // 随机位置和动画时长 snowflake.style.left = `${Math.random() * 100}vw`; snowflake.style.animationDuration = `${Math.random() * 10 + 10}s`; snowflake.style.animationDelay = `${Math.random() * 10}s`; snowflake.style.fontSize = `${Math.random() * 1 + 0.5}rem`; document.body.appendChild(snowflake); } } // 页面加载完成后生成雪花 window.onload = createSnowflakes; </script> </body> </html>相关阅读: