设计模板预览

在查看代码之前,我们先来想象一下这个模板的布局和风格:

美食网页设计模板及代码div css
(图片来源网络,侵删)
  1. 顶部导航栏:包含网站Logo、主导航菜单(首页、菜单、关于我们、联系我们)和一个用户操作区(如登录/注册按钮)。
  2. 主视觉横幅:一张高质量的美食图片作为背景,上面有吸引人的标题和号召性用语(如“探索味蕾的奇妙旅程”)。
  3. 特色菜品推荐:以网格布局展示几道招牌菜,每道菜包含图片、名称、简短描述和价格。
  4. 关于我们/故事:一个图文并茂的区域,介绍餐厅的理念、历史或主厨故事,增加品牌温度。
  5. 客户评价:展示一些食客的好评,通常使用引言样式,增加信任感。
  6. 页脚:包含餐厅的联系方式、地址、营业时间、社交媒体图标和版权信息。

风格特点

  • 配色:以暖色调为主,如 #E85D04 (橙色) 作为主色,搭配 #333333 (深灰) 作为文字色,#F5F5F5 (浅灰) 作为背景色,营造温馨、有食欲的氛围。
  • 字体使用粗体、现代的无衬线字体(如 Montserrat),正文使用清晰易读的无衬线字体(如 Open Sans)。
  • 布局:清晰、简洁,留白充足,重点突出。

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>
    <!-- 引入 Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@700&family=Open+Sans:wght@400;600&display=swap" rel="stylesheet">
    <!-- 引入 Font Awesome 图标库 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <!-- 顶部导航栏 -->
    <header class="main-header">
        <div class="container header-container">
            <div class="logo">
                <a href="#">味蕾盛宴</a>
            </div>
            <nav class="main-nav">
                <ul>
                    <li><a href="#home">首页</a></li>
                    <li><a href="#menu">菜单</a></li>
                    <li><a href="#about">关于我们</a></li>
                    <li><a href="#contact">联系我们</a></li>
                </ul>
            </nav>
            <div class="user-actions">
                <a href="#" class="btn-login">登录</a>
                <a href="#" class="btn-register">注册</a>
            </div>
        </div>
    </header>
    <main>
        <!-- 主视觉横幅 -->
        <section id="home" class="hero-banner">
            <div class="hero-content">
                <h1>探索味蕾的奇妙旅程</h1>
                <p>每一道菜,都是一个故事;每一次品尝,都是一次享受。</p>
                <a href="#menu" class="btn-menu">查看菜单</a>
            </div>
        </section>
        <!-- 特色菜品推荐 -->
        <section id="menu" class="featured-dishes">
            <div class="container">
                <h2 class="section-title">招牌推荐</h2>
                <div class="dishes-grid">
                    <div class="dish-card">
                        <img src="https://via.placeholder.com/300x200/FFC107/FFFFFF?text=红烧肉" alt="招牌红烧肉">
                        <h3>招牌红烧肉</h3>
                        <p>肥而不腻,入口即化,传统工艺精心慢炖。</p>
                        <p class="price">¥68</p>
                    </div>
                    <div class="dish-card">
                        <img src="https://via.placeholder.com/300x200/4CAF50/FFFFFF?text=清蒸鲈鱼" alt="清蒸鲈鱼">
                        <h3>清蒸鲈鱼</h3>
                        <p>鱼肉鲜嫩,原汁原味,保留海洋的鲜美。</p>
                        <p class="price">¥98</p>
                    </div>
                    <div class="dish-card">
                        <img src="https://via.placeholder.com/300x200/FF5722/FFFFFF?text=宫保鸡丁" alt="宫保鸡丁">
                        <h3>宫保鸡丁</h3>
                        <p>麻辣鲜香,花生酥脆,川味经典,回味无穷。</p>
                        <p class="price">¥58</p>
                    </div>
                </div>
            </div>
        </section>
        <!-- 关于我们 -->
        <section id="about" class="about-us">
            <div class="container">
                <div class="about-content">
                    <div class="about-text">
                        <h2>我们的故事</h2>
                        <p>“味蕾盛宴”始于2010年,由主厨李明先生创立,怀着对美食的无限热爱与执着,我们坚持使用最新鲜的食材,最传统的烹饪技艺,只为将最地道的味道呈现给每一位食客。</p>
                        <p>我们不只是在做菜,更是在创造一种美好的用餐体验,您可以卸下疲惫,与家人朋友共享美食,创造属于你们的美好回忆。</p>
                    </div>
                    <div class="about-image">
                        <img src="https://via.placeholder.com/500x400/9C27B0/FFFFFF?text=餐厅环境" alt="餐厅环境">
                    </div>
                </div>
            </div>
        </section>
        <!-- 客户评价 -->
        <section class="testimonials">
            <div class="container">
                <h2 class="section-title">食客好评</h2>
                <div class="testimonials-grid">
                    <div class="testimonial-card">
                        <i class="fas fa-quote-left"></i>
                        <p>红烧肉太绝了!是我吃过最好吃的,下次朋友聚会还来这里!</p>
                        <div class="customer-info">
                            <img src="https://via.placeholder.com/50x50/795548/FFFFFF?text=张" alt="顾客头像">
                            <span>张先生</span>
                        </div>
                    </div>
                    <div class="testimonial-card">
                        <i class="fas fa-quote-left"></i>
                        <p>环境优雅,服务周到,菜品精致,非常适合情侣约会。</p>
                        <div class="customer-info">
                            <img src="https://via.placeholder.com/50x50/FF4081/FFFFFF?text=李" alt="顾客头像">
                            <span>李女士</span>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>
    <!-- 页脚 -->
    <footer class="main-footer">
        <div class="container">
            <div class="footer-content">
                <div class="footer-section">
                    <h3>联系我们</h3>
                    <p><i class="fas fa-map-marker-alt"></i> 北京市朝阳区美食街88号</p>
                    <p><i class="fas fa-phone"></i> 010-12345678</p>
                    <p><i class="fas fa-envelope"></i> info@weileishengyan.com</p>
                </div>
                <div class="footer-section">
                    <h3>营业时间</h3>
                    <p>周一至周五: 11:00 - 22:00</p>
                    <p>周六至周日: 10:00 - 23:00</p>
                </div>
                <div class="footer-section">
                    <h3>关注我们</h3>
                    <div class="social-links">
                        <a href="#"><i class="fab fa-weixin"></i></a>
                        <a href="#"><i class="fab fa-weibo"></i></a>
                        <a href="#"><i class="fab fa-tiktok"></i></a>
                    </div>
                </div>
            </div>
            <div class="footer-bottom">
                <p>&copy; 2025 味蕾盛宴. All rights reserved.</p>
            </div>
        </div>
    </footer>
</body>
</html>

CSS 样式代码

下面是配套的 CSS 代码,请将此代码保存为与 HTML 文件同目录下的 style.css 文件。

/* --- 全局样式和变量 --- */
:root {
    --primary-color: #E85D04; /* 主色调:橙色 */
    --secondary-color: #333333; /* 次要色:深灰 */
    --light-color: #F5F5F5; /* 浅色背景 */
    --text-color: #555555; /* 正文颜色 */
    --box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
html {
    scroll-behavior: smooth; /* 平滑滚动 */
}
body {
    font-family: 'Open Sans', sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: #fff;
}
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}
h1, h2, h3 {
    font-family: 'Montserrat', sans-serif;
    color: var(--secondary-color);
    margin-bottom: 1rem;
}
h2.section-title {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 3rem;
    position: relative;
}
h2.section-title::after {
    content: '';
    display: block;
    width: 80px;
    height: 4px;
    background-color: var(--primary-color);
    margin: 1rem auto;
}
a {
    text-decoration: none;
    color: inherit;
}
img {
    max-width: 100%;
    height: auto;
    display: block;
}
.btn {
    display: inline-block;
    padding: 12px 25px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 5px;
    font-weight: 600;
    transition: background-color 0.3s ease, transform 0.3s ease;
}
.btn:hover {
    background-color: #c44d03;
    transform: translateY(-2px);
}
/* --- 布局组件 --- */
.section-title {
    text-align: center;
    font-size: 2.5rem;
    margin-bottom: 3rem;
    position: relative;
}
.section-title::after {
    content: '';
    display: block;
    width: 80px;
    height: 4px;
    background-color: var(--primary-color);
    margin: 1rem auto;
}
.grid-2-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: center;
}
/* --- 顶部导航栏 --- */
.main-header {
    background-color: white;
    box-shadow: var(--box-shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}
.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
}
.logo a {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
}
.main-nav ul {
    list-style: none;
    display: flex;
    gap: 2rem;
}
.main-nav a {
    font-weight: 600;
    color: var(--secondary-color);
    transition: color 0.3s ease;
}
.main-nav a:hover {
    color: var(--primary-color);
}
.user-actions .btn-login {
    color: var(--primary-color);
    font-weight: 600;
    border: 2px solid var(--primary-color);
    padding: 8px 20px;
    border-radius: 5px;
    transition: all 0.3s ease;
}
.user-actions .btn-login:hover {
    background-color: var(--primary-color);
    color: white;
}
.user-actions .btn-register {
    background-color: var(--primary-color);
    color: white;
    padding: 8px 20px;
    border-radius: 5px;
    margin-left: 1rem;
    transition: background-color 0.3s ease;
}
.user-actions .btn-register:hover {
    background-color: #c44d03;
}
/* --- 主视觉横幅 --- */
.hero-banner {
    height: 90vh;
    background: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)), url('https://via.placeholder.com/1920x1080/FF9800/FFFFFF?text=美食横幅') no-repeat center center/cover;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: white;
}
.hero-content h1 {
    font-size: 3.5rem;
    margin-bottom: 1rem;
}
.hero-content p {
    font-size: 1.2rem;
    margin-bottom: 2rem;
}
.btn-menu {
    background-color: var(--primary-color);
    color: white;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 600;
}
/* --- 特色菜品推荐 --- */
.featured-dishes {
    padding: 5rem 0;
    background-color: var(--light-color);
}
.dishes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}
.dish-card {
    background-color: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--box-shadow);
    transition: transform 0.3s ease;
}
.dish-card:hover {
    transform: translateY(-10px);
}
.dish-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}
.dish-card-content {
    padding: 1.5rem;
}
.dish-card h3 {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}
.dish-card p {
    color: var(--text-color);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.price {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}
/* --- 关于我们 --- */
.about-us {
    padding: 5rem 0;
}
.about-content {
    display: flex;
    align-items: center;
    gap: 3rem;
}
.about-image {
    flex: 1;
}
.about-text {
    flex: 1;
}
.about-text p {
    margin-bottom: 1rem;
}
/* --- 客户评价 --- */
.testimonials {
    padding: 5rem 0;
    background-color: var(--light-color);
}
.testimonials-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}
.testimonial-card {
    background-color: white;
    padding: 2rem;
    border-radius: 10px;
    box-shadow: var(--box-shadow);
    position: relative;
}
.testimonial-card i {
    color: var(--primary-color);
    font-size: 2rem;
    position: absolute;
    top: 1rem;
    left: 1rem;
    opacity: 0.2;
}
.testimonial-card p {
    font-style: italic;
    margin-bottom: 1.5rem;
}
.customer-info {
    display: flex;
    align-items: center;
}
.customer-info img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 1rem;
}
/* --- 页脚 --- */
.main-footer {
    background-color: var(--secondary-color);
    color: white;
    padding: 3rem 0 1rem;
}
.footer-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}
.footer-section h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
}
.footer-section p, .footer-section a {
    margin-bottom: 0.5rem;
    transition: color 0.3s ease;
}
.footer-section a:hover {
    color: var(--primary-color);
}
.social-links a {
    color: white;
    font-size: 1.5rem;
    margin-right: 1rem;
    transition: color 0.3s ease;
}
.social-links a:hover {
    color: var(--primary-color);
}
.footer-bottom {
    text-align: center;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
    color: #ccc;
}
/* --- 响应式设计 --- */
@media (max-width: 768px) {
    .header-container {
        flex-direction: column;
        gap: 1rem;
    }
    .main-nav ul {
        gap: 1rem;
    }
    .hero-content h1 {
        font-size: 2.5rem;
    }
    .about-content {
        flex-direction: column;
    }
    .footer-content {
        grid-template-columns: 1fr;
        text-align: center;
    }
    .social-links {
        justify-content: center;
    }
}

如何使用

  1. 创建文件:在你的项目文件夹中,创建两个文件:index.htmlstyle.css
  2. 复制代码:将上面的 HTML 代码完整地复制到 index.html 文件中。
  3. 复制代码:将上面的 CSS 代码完整地复制到 style.css 文件中。
  4. 放置图片:代码中使用了 placeholder.com 的占位图,你可以下载自己喜欢的美食图片、Logo 等,替换掉 src 属性中的链接。
  5. 打开浏览器:用浏览器打开 index.html 文件,你就可以看到一个功能完整、样式精美的美食网页了。

进阶建议

  • JavaScript 交互:可以添加一些 JavaScript 来实现更复杂的功能,
    • 导航栏高亮:当用户滚动到不同区域时,导航栏对应的链接高亮显示。
    • 图片懒加载:优化页面加载速度,只有当图片进入可视区域时才加载。
    • 轮播图:将主视觉横幅做成一个可以自动切换的轮播图。
    • 表单验证:在“联系我们”或“注册”页面添加表单验证功能。
  • 响应式优化:CSS 已经包含了基础的响应式设计,你可以根据不同设备(如平板、手机)进行更细致的调整。
  • 动画效果:使用 CSS @keyframes 或 JavaScript 动画库(如 AOS)为页面元素添加进入、滚动等动画,提升用户体验。

这个模板为你提供了一个坚实的基础,你可以根据自己的具体需求进行修改和扩展,打造出独一无二的美食网站。

美食网页设计模板及代码div css
(图片来源网络,侵删)
美食网页设计模板及代码div css
(图片来源网络,侵删)