写一个css+html+js 的高级网页,网页内容美食

时间: 2024-03-05 10:52:56 浏览: 18
好的,以下是一个简单的美食网页的 HTML、CSS、JavaScript 代码示例,实现了轮播图、鼠标悬停效果、弹出框等功能。 HTML 代码: ```html <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>美食网站</title> <link rel="stylesheet" href="style.css"> </head> <body> <header> <nav> <ul> <li><a href="#">首页</a></li> <li><a href="#">热门美食</a></li> <li><a href="#">最新菜谱</a></li> <li><a href="#">美食视频</a></li> <li><a href="#">联系我们</a></li> </ul> </nav> </header> <main> <div class="slideshow"> <img src="food1.jpg" alt="美食1"> <img src="food2.jpg" alt="美食2"> <img src="food3.jpg" alt="美食3"> <img src="food4.jpg" alt="美食4"> </div> <h1>热门美食推荐</h1> <ul class="food-list"> <li> <img src="food5.jpg" alt="美食5"> <h3>美食5</h3> <p>描述美食5的信息。</p> <button class="btn">查看详情</button> </li> <li> <img src="food6.jpg" alt="美食6"> <h3>美食6</h3> <p>描述美食6的信息。</p> <button class="btn">查看详情</button> </li> <li> <img src="food7.jpg" alt="美食7"> <h3>美食7</h3> <p>描述美食7的信息。</p> <button class="btn">查看详情</button> </li> <li> <img src="food8.jpg" alt="美食8"> <h3>美食8</h3> <p>描述美食8的信息。</p> <button class="btn">查看详情</button> </li> </ul> </main> <footer> <p>版权所有 © 美食网站</p> </footer> <div class="overlay"> <div class="modal"> <h2>美食详情</h2> <img src="food9.jpg" alt="美食9"> <p>描述美食9的信息。</p> <button class="close-btn">×</button> </div> </div> <script src="script.js"></script> </body> </html> ``` CSS 代码: ```css /* Reset styles */ * { margin: 0; padding: 0; box-sizing: border-box; } /* Header styles */ header { background-color: #333; color: #fff; padding: 20px; } nav ul { list-style: none; display: flex; } nav li { margin-right: 20px; } nav a { color: #fff; text-decoration: none; } /* Main styles */ .slideshow { width: 100%; height: 500px; overflow: hidden; position: relative; } .slideshow img { width: 100%; height: 100%; position: absolute; top: 0; left: 0; opacity: 0; transition: opacity 1s ease-in-out; } .slideshow img.active { opacity: 1; } h1 { text-align: center; margin: 50px 0; } .food-list { list-style: none; display: flex; flex-wrap: wrap; justify-content: center; } .food-list li { margin: 30px; position: relative; width: 300px; height: 400px; } .food-list li:hover .btn { bottom: 20px; } .food-list img { width: 100%; height: 300px; object-fit: cover; } .food-list h3 { margin: 20px 0; } .btn { position: absolute; bottom: -50px; left: 50%; transform: translateX(-50%); background-color: #333; color: #fff; border: none; padding: 10px 20px; cursor: pointer; transition: bottom 0.5s ease-in-out; } /* Footer styles */ footer { background-color: #333; color: #fff; padding: 20px; margin-top: 50px; text-align: center; } /* Overlay styles */ .overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: none; justify-content: center; align-items: center; } .modal { width: 500px; background-color: #fff; padding: 20px; text-align: center; position: relative; } .modal img { width: 100%; height: 300px; object-fit: cover; } .modal h2 { margin-bottom: 20px; } .close-btn { position: absolute; top: 10px; right: 10px; background-color: transparent; border: none; font-size: 30px; cursor: pointer; } ``` JavaScript 代码: ```javascript // Get slideshow images const slideshow = document.querySelector('.slideshow'); const images = slideshow.querySelectorAll('img'); let currentIndex = 0; // Set active class to first image images[currentIndex].classList.add('active'); // Change image every 3 seconds setInterval(() => { images[currentIndex].classList.remove('active'); currentIndex = (currentIndex + 1) % images.length; images[currentIndex].classList.add('active'); }, 3000); // Show modal when button is clicked const overlay = document.querySelector('.overlay'); const modal = document.querySelector('.modal'); const closeBtn = modal.querySelector('.close-btn'); const buttons = document.querySelectorAll('.btn'); buttons.forEach((button) => { button.addEventListener('click', () => { overlay.style.display = 'flex'; modal.style.display = 'block'; }); }); // Hide modal when close button is clicked closeBtn.addEventListener('click', () => { overlay.style.display = 'none'; modal.style.display = 'none'; }); // Hide modal when overlay is clicked overlay.addEventListener('click', (event) => { if (event.target === overlay) { overlay.style.display = 'none'; modal.style.display = 'none'; } }); ``` 请注意,这只是一个简单的示例代码,实际网页需要根据需求进行优化和完善,比如添加更多的美食信息、优化页面布局等等。

相关推荐

最新推荐

recommend-type

前端HTML5+CSS+JavaScript学习笔记.docx

前端HTML5+CSS+JavaScript详细学习笔记,来自菜鸟教程、w3cSchool和b站视频教程的总结,包括基础知识和示例代码,欢迎大家指正
recommend-type

韩顺平《轻松搞定网页设计HTML+CSS+JAVASCRIPT》之Javascript学习笔记

韩顺平《轻松搞定网页设计HTML+CSS+JAVASCRIPT》之Javascript学习笔记
recommend-type

纯js+html和纯css+html制作手风琴效果

本文分享了纯js+html制作手风琴和纯css+html制作手风琴两种效果,供大家参考,具体内容如下 一、纯css+html的手风琴效果 这种用css写的手风琴比较简单,主要是应用到css中的,transition属性。 代码如下: &lt;!...
recommend-type

HTML+CSS+JavaScript网页制作案例教程(第2版)_教学大纲.doc

HTML+CSS+JavaScript网页制作案例教程(第2版)_教学大纲.doc
recommend-type

利用js+css+html实现固定table的列头不动

话不多说,跟这小编来一起看下吧 ... //该函数在上面一个table数据加载完成后调用 //把表头的宽度设置到会滚动的页头去 var copyWidth = function () { var b = $('#data_tbody').prev().find('tr:last').fi
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。