作业主题:喜迎新春 - 龙年大吉

设计目标: 创建一个充满节日气氛、视觉冲击力强的春节主题网页,页面应包含核心的春节元素(如红包、灯笼、鞭炮、烟花等),并具备互动性,让访问者感受到浓浓的年味。

html网页设计作业春节主题
(图片来源网络,侵删)

技术栈:

  • HTML5: 用于构建页面结构和内容。
  • CSS3: 用于美化页面、实现动画效果和响应式布局。
  • JavaScript (原生): 用于实现交互功能,如倒计时、许愿池、祝福语滚动等。

第一步:页面结构设计

在开始写代码之前,先规划一下页面的布局,一个完整的网页应该包含以下几个部分:

  1. 顶部区域:
    • (龙年大吉,万事如意)
    • 倒计时模块(距离春节还有多少天)
  2. 主视觉区域:
    • 一个巨大的、动态的标题或Logo。
    • 背景可以是动态的烟花或飘落的雪花/花瓣。
  3. 祝福/许愿区:
    • 一个输入框,让用户输入新年愿望。
    • 一个提交按钮,点击后愿望会“飞”到屏幕上方的愿望墙。
  4. 春节习俗介绍区:

    以卡片或轮播图的形式,简单介绍春节的几个习俗(如:贴春联、吃年夜饭、守岁、拜年)。

  5. 底部区域:

    页脚,包含版权信息和一些装饰性元素。

    html网页设计作业春节主题
    (图片来源网络,侵删)

第二步:HTML 代码实现

下面是上述结构的HTML代码,请将以下代码保存为 index.html 文件。

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">喜迎新春 - 龙年大吉</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <!-- 顶部区域 -->
    <header>
        <div class="container">
            <h1>🐉 龙年大吉 🧧</h1>
            <div id="countdown" class="countdown">
                <p>距离甲辰龙年还有:</p>
                <div class="time">
                    <span id="days">00</span> 天
                    <span id="hours">00</span> 时
                    <span id="minutes">00</span> 分
                    <span id="seconds">00</span> 秒
                </div>
            </div>
        </div>
    </header>
    <!-- 主视觉区域 -->
    <main>
        <section class="hero">
            <div class="lanterns">
                <div class="lantern"></div>
                <div class="lantern"></div>
            </div>
            <h2 class="main-title">恭贺新禧</h2>
            <p>愿新的一年,平安喜乐,万事顺遂!</p>
        </section>
        <!-- 祝福/许愿区 -->
        <section class="wishing-well">
            <div class="container">
                <h2>新年许愿</h2>
                <div class="well-form">
                    <input type="text" id="wish-input" placeholder="写下你的新年愿望..." maxlength="50">
                    <button id="submit-wish">许愿</button>
                </div>
            </div>
            <div id="wishes-container" class="wishes-container"></div>
        </section>
        <!-- 春节习俗介绍区 -->
        <section class="customs">
            <div class="container">
                <h2>春节习俗</h2>
                <div class="customs-grid">
                    <div class="custom-card">
                        <div class="card-icon">🧧</div>
                        <h3>发红包</h3>
                        <p>压岁钱,相传能压住邪祟,保佑孩子平安健康。</p>
                    </div>
                    <div class="custom-card">
                        <div class="card-icon">🏮</div>
                        <h3>挂灯笼</h3>
                        <p>象征着团圆和红火,寓意新的一年生活红红火火。</p>
                    </div>
                    <div class="custom-card">
                        <div class="card-icon">🎇</div>
                        <h3>放烟花</h3>
                        <p>爆竹声中一岁除,用热闹驱赶邪祟,迎接新年。</p>
                    </div>
                    <div class="custom-card">
                        <div class="card-icon">🍲</div>
                        <h3>年夜饭</h3>
                        <p>全家人团聚在一起,共享丰盛的晚餐,寓意团圆美满。</p>
                    </div>
                </div>
            </div>
        </section>
    </main>
    <!-- 底部区域 -->
    <footer>
        <p>&copy; 2025 新春快乐. All Rights Reserved.</p>
    </footer>
    <script src="script.js"></script>
</body>
</html>

第三步:CSS 样式与美化

这是让网页变美的关键,请将以下代码保存为 style.css 文件,并与 index.html 放在同一目录下。

/* --- 全局样式 --- */
@import url('https://fonts.googleapis.com/css2?family=ZCOOL+XiaoWei&display=swap');
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    font-family: 'ZCOOL XiaoWei', serif; /* 使用一个有中国风的字体 */
    background-color: #c41e3a; /* 春节红色背景 */
    color: #fff;
    overflow-x: hidden;
    line-height: 1.6;
}
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}
/* --- 顶部区域 --- */
header {
    text-align: center;
    padding: 30px 0;
    background-color: rgba(0, 0, 0, 0.3);
}
header h1 {
    font-size: 3em;
    margin-bottom: 20px;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.5);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}
.countdown {
    font-size: 1.2em;
}
.countdown .time {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
}
.countdown .time span {
    background-color: #ffd700;
    color: #c41e3a;
    padding: 10px 15px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.2em;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
/* --- 主视觉区域 --- */
.hero {
    position: relative;
    height: 500px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: linear-gradient(rgba(0,0,0,0.4), rgba(0,0,0,0.4)), url('https://images.unsplash.com/photo-1518531933835-7113b8b00594?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1770&q=80') no-repeat center center/cover;
    color: #fff;
}
.main-title {
    font-size: 5em;
    margin-bottom: 20px;
    text-shadow: 5px 5px 10px rgba(0, 0, 0, 0.7);
}
/* 灯笼装饰 */
.lanterns {
    position: absolute;
    top: 50px;
    width: 100%;
    display: flex;
    justify-content: space-around;
}
.lantern {
    width: 60px;
    height: 80px;
    background-color: #ff4d4f;
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    position: relative;
    box-shadow: 0 0 20px #ff4d4f;
    animation: swing 3s ease-in-out infinite;
}
.lantern:nth-child(2) {
    animation-delay: 1.5s;
}
@keyframes swing {
    0%, 100% { transform: rotate(-5deg); }
    50% { transform: rotate(5deg); }
}
/* --- 许愿区 --- */
.wishing-well {
    padding: 60px 0;
    text-align: center;
}
.well-form {
    max-width: 600px;
    margin: 20px auto;
    display: flex;
    gap: 10px;
}
#wish-input {
    flex-grow: 1;
    padding: 15px;
    font-size: 1.1em;
    border: none;
    border-radius: 50px;
    outline: none;
}
#submit-wish {
    padding: 15px 30px;
    font-size: 1.1em;
    border: none;
    border-radius: 50px;
    background-color: #ffd700;
    color: #c41e3a;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.3s, background-color 0.3s;
}
#submit-wish:hover {
    transform: scale(1.1);
    background-color: #ffed4e;
}
.wishes-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* 允许点击穿透 */
    z-index: 10;
}
.wish-item {
    position: absolute;
    color: #ffd700;
    font-size: 1.2em;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
    animation: float-up 8s linear forwards;
}
@keyframes float-up {
    0% {
        transform: translateY(100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(-100px) rotate(360deg);
        opacity: 0;
    }
}
/* --- 习俗区 --- */
.customs {
    padding: 60px 0;
    background-color: rgba(0, 0, 0, 0.2);
}
.customs h2 {
    text-align: center;
    font-size: 2.5em;
    margin-bottom: 40px;
}
.customs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 30px;
}
.custom-card {
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    backdrop-filter: blur(5px);
    transition: transform 0.3s, box-shadow 0.3s;
}
.custom-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}
.card-icon {
    font-size: 3em;
    margin-bottom: 15px;
}
/* --- 底部区域 --- */
footer {
    text-align: center;
    padding: 20px;
    background-color: rgba(0, 0, 0, 0.5);
}
/* --- 响应式设计 --- */
@media (max-width: 768px) {
    header h1 {
        font-size: 2em;
    }
    .main-title {
        font-size: 3em;
    }
    .well-form {
        flex-direction: column;
    }
    #wish-input, #submit-wish {
        width: 100%;
    }
}

第四步:JavaScript 交互功能

我们用 JavaScript 来实现倒计时和许愿功能,请将以下代码保存为 script.js 文件,与 index.htmlstyle.css 放在同一目录下。

document.addEventListener('DOMContentLoaded', () => {
    // --- 倒计时功能 ---
    const countdownElement = document.getElementById('countdown');
    const daysElement = document.getElementById('days');
    const hoursElement = document.getElementById('hours');
    const minutesElement = document.getElementById('minutes');
    const secondsElement = document.getElementById('seconds');
    // 设置春节日期 (2025年1月29日)
    const newYearDate = new Date('January 29, 2025 00:00:00').getTime();
    function updateCountdown() {
        const now = new Date().getTime();
        const distance = newYearDate - now;
        if (distance < 0) {
            countdownElement.innerHTML = "<p>🎉 新年快乐! 🎉</p>";
            return;
        }
        const days = Math.floor(distance / (1000 * 60 * 60 * 24));
        const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        const seconds = Math.floor((distance % (1000 * 60)) / 1000);
        daysElement.textContent = String(days).padStart(2, '0');
        hoursElement.textContent = String(hours).padStart(2, '0');
        minutesElement.textContent = String(minutes).padStart(2, '0');
        secondsElement.textContent = String(seconds).padStart(2, '0');
    }
    // 每秒更新一次倒计时
    setInterval(updateCountdown, 1000);
    updateCountdown(); // 立即执行一次
    // --- 许愿功能 ---
    const wishInput = document.getElementById('wish-input');
    const submitWishButton = document.getElementById('submit-wish');
    const wishesContainer = document.getElementById('wishes-container');
    submitWishButton.addEventListener('click', makeAWish);
    wishInput.addEventListener('keypress', (e) => {
        if (e.key === 'Enter') {
            makeAWish();
        }
    });
    function makeAWish() {
        const wishText = wishInput.value.trim();
        if (wishText === '') {
            alert('请输入你的愿望哦!');
            return;
        }
        // 创建愿望元素
        const wishItem = document.createElement('div');
        wishItem.className = 'wish-item';
        wishItem.textContent = wishText;
        // 随机位置
        const xPos = Math.random() * (window.innerWidth - 200);
        wishItem.style.left = `${xPos}px`;
        // 添加到容器
        wishesContainer.appendChild(wishItem);
        // 清空输入框
        wishInput.value = '';
        // 8秒后移除元素,避免内存泄漏
        setTimeout(() => {
            wishItem.remove();
        }, 8000);
    }
});

如何运行和展示

  1. 创建文件夹: 在你的电脑上创建一个新文件夹,spring-festival
  2. 保存文件: 将上面三个代码块分别保存为 index.htmlstyle.cssscript.js,并全部放入 spring-festival 文件夹中。
  3. 打开网页: 找到 index.html 文件,用浏览器(如 Chrome, Firefox, Edge)直接打开它。

你就能看到一个完整、美观、可交互的春节主题网页了!

html网页设计作业春节主题
(图片来源网络,侵删)

进阶与扩展建议

如果你想让作业更出彩,可以尝试以下扩展:

  1. 添加背景音乐:<body> 标签内添加 <audio src="path/to/your/music.mp3" autoplay loop></audio>
  2. 实现烟花效果: 使用 Canvas 或 CSS 动画创建一个点击屏幕就会放烟花的交互效果。
  3. 制作春联/福字: 用 CSS 3D 变换制作一个可以旋转的立体“福”字,或者一副可以翻开的春联。
  4. “集五福”小游戏: 设计一个简单的点击收集“福禄寿喜财”五个福卡的小游戏。
  5. 更多动画: 让红包从天而降,或者让鞭炮在页脚自动“爆炸”。

希望这份详细的指南能帮助你完成一份出色的春节主题网页设计作业!祝你新年快乐,学业有成!