请利用HTML、CSS和JavaScript这三种编程语言制作一个简单的网页,至少要100行代码
时间: 2024-04-01 13:35:58 浏览: 94
好的,以下是一个简单的网页示例,包括一个导航栏、一个轮播图、一个新闻列表和一个联系我们的表单。这个示例使用HTML、CSS和JavaScript这三种编程语言,共计超过100行代码。
HTML代码:
```
<!DOCTYPE html>
<html>
<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>
</ul>
</nav>
</header>
<main>
<div class="slideshow-container">
<div class="slideshow-slide fade">
<img src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__480.jpg" alt="一棵树的图片">
</div>
<div class="slideshow-slide fade">
<img src="https://cdn.pixabay.com/photo/2015/03/26/09/54/forest-690058__480.jpg" alt="一片森林的图片">
</div>
<div class="slideshow-slide fade">
<img src="https://cdn.pixabay.com/photo/2018/11/29/21/19/hamburg-3846525__480.jpg" alt="一张城市的图片">
</div>
<a class="slideshow-prev" onclick="plusSlides(-1)">❮</a>
<a class="slideshow-next" onclick="plusSlides(1)">❯</a>
</div>
<br>
<div style="text-align:center">
<span class="slideshow-dot" onclick="currentSlide(1)"></span>
<span class="slideshow-dot" onclick="currentSlide(2)"></span>
<span class="slideshow-dot" onclick="currentSlide(3)"></span>
</div>
<hr>
<h2>最新新闻</h2>
<ul>
<li>2019年新产品发布会圆满结束</li>
<li>公司CEO简历更新</li>
<li>公司获得新一轮融资</li>
<li>全球销售额突破1亿美元</li>
</ul>
<hr>
<h2>联系我们</h2>
<form>
<label for="name">姓名:</label>
<input type="text" id="name" name="name"><br>
<label for="email">邮箱:</label>
<input type="email" id="email" name="email"><br>
<label for="message">留言:</label>
<textarea id="message" name="message"></textarea><br>
<button type="submit">提交</button>
</form>
</main>
<script src="script.js"></script>
</body>
</html>
```
CSS代码:
```
nav ul {
list-style: none;
margin: 0;
padding: 0;
background-color: #333;
overflow: hidden;
}
nav li {
float: left;
}
nav li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
nav li a:hover {
background-color: #111;
}
.slideshow-container {
max-width: 800px;
position: relative;
margin: auto;
}
.slideshow-slide {
display: none;
}
.slideshow-slide img {
width: 100%;
height: 400px;
object-fit: cover;
}
.slideshow-prev, .slideshow-next {
position: absolute;
top: 50%;
transform: translateY(-50%);
cursor: pointer;
padding: 16px;
color: white;
font-weight: bold;
font-size: 24px;
}
.slideshow-prev {
left: 0;
}
.slideshow-next {
right: 0;
}
.slideshow-dot {
display: inline-block;
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
}
.slideshow-active, .slideshow-dot:hover {
background-color: #717171;
}
form label {
display: inline-block;
width: 80px;
}
form input[type=text], form input[type=email], form textarea {
width: 100%;
padding: 12px;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
margin-bottom: 16px;
resize: vertical;
}
form button[type=submit] {
background-color: #4CAF50;
color: white;
padding: 12px 20px;
border: none;
border-radius: 4px;
cursor: pointer;
}
form button[type=submit]:hover {
background-color: #45a049;
}
```
JavaScript代码:
```
var slideIndex = 1;
showSlides(slideIndex);
function plusSlides(n) {
showSlides(slideIndex += n);
}
function currentSlide(n) {
showSlides(slideIndex = n);
}
function showSlides(n) {
var i;
var slides = document.getElementsByClassName("slideshow-slide");
var dots = document.getElementsByClassName("slideshow-dot");
if (n > slides.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = slides.length
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" slideshow-active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " slideshow-active";
}
```
这个网页示例包括一个导航栏、一个轮播图、一个新闻列表和一个联系我们的表单。其中,导航栏使用了HTML的`<nav>`和`<ul>`标签以及CSS的浮动布局来实现,轮播图使用了JavaScript来实现,新闻列表使用了HTML的`<ul>`和`<li>`标签来实现,联系我们的表单使用了HTML的`<form>`、`<label>`、`<input>`和`<textarea>`标签以及CSS来实现。整个网页使用了CSS的样式表来美化,包括导航栏、轮播图、新闻列表和联系我们的表单。
阅读全文