写一个具有下拉式导航栏,图片轮播和foot的博客网站
时间: 2024-02-27 08:51:32 浏览: 66
好的,以下是一个具有下拉式导航栏,图片轮播和foot的博客网站的HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>博客网站</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* 样式重置 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 全局样式 */
body {
font-family: Arial, sans-serif;
background-color: #f1f1f1;
}
.container {
width: 80%;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0px 4px 8px 0px rgba(0,0,0,0.2);
}
h1 {
font-size: 36px;
font-weight: bold;
text-align: center;
margin: 20px 0;
}
h2 {
font-size: 24px;
font-weight: bold;
margin: 20px 0 10px 0;
}
p {
line-height: 1.5;
margin-bottom: 20px;
}
img {
max-width: 100%;
}
/* 导航栏样式 */
.navbar {
background-color: #333;
overflow: hidden;
}
.navbar a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: #f2f2f2;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: #ddd;
color: black;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* 图片轮播样式 */
.slideshow {
position: relative;
width: 100%;
height: 400px;
overflow: hidden;
margin-bottom: 20px;
}
.slideshow img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
transition: opacity 1s ease-in-out;
}
.slideshow img.active {
opacity: 1;
z-index: 1;
}
.slideshow .arrow {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 50px;
height: 50px;
background-color: #fff;
text-align: center;
cursor: pointer;
transition: background-color 0.3s ease-in-out;
}
.slideshow .arrow:hover {
background-color: #f1f1f1;
}
.slideshow .arrow.left {
left: 0;
}
.slideshow .arrow.right {
right: 0;
}
/* 底部样式 */
.footer {
background-color: #333;
color: #fff;
padding: 20px;
text-align: center;
}
.footer p {
margin-bottom: 0;
}
</style>
</head>
<body>
<!-- 导航栏 -->
<div class="navbar">
<a href="#">首页</a>
<a href="#">文章</a>
<a href="#">分类</a>
<div class="dropdown">
<button class="dropbtn">关于</button>
<div class="dropdown-content">
<a href="#">作者</a>
<a href="#">网站</a>
</div>
</div>
<a href="#" style="float:right">登录</a>
</div>
<!-- 内容 -->
<div class="container">
<!-- 图片轮播 -->
<div class="slideshow">
<img src="https://picsum.photos/id/1015/600/400" alt="" class="active">
<img src="https://picsum.photos/id/1016/600/400" alt="">
<img src="https://picsum.photos/id/1018/600/400" alt="">
<div class="arrow left">❮</div>
<div class="arrow right">❯</div>
</div>
<!-- 文章 -->
<h1>最新文章</h1>
<div>
<h2>文章标题</h2>
<img src="https://picsum.photos/id/1024/600/400" alt="">
<p>这里是文章内容...</p>
<a href="#">阅读更多</a>
<hr>
</div>
<div>
<h2>文章标题</h2>
<img src="https://picsum.photos/id/1033/600/400" alt="">
<p>这里是文章内容...</p>
<a href="#">阅读更多</a>
<hr>
</div>
<div>
<h2>文章标题</h2>
<img src="https://picsum.photos/id/1047/600/400" alt="">
<p>这里是文章内容...</p>
<a href="#">阅读更多</a>
<hr>
</div>
</div>
<!-- 底部 -->
<div class="footer">
<p>版权 © 2021 博客网站</p>
</div>
<script>
let slideIndex = 0;
showSlides();
function showSlides() {
let i;
let slides = document.getElementsByClassName("slideshow")[0].getElementsByTagName("img");
for (i = 0; i < slides.length; i++) {
slides[i].classList.remove("active");
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1;
}
slides[slideIndex-1].classList.add("active");
setTimeout(showSlides, 3000); // 切换时间间隔为3秒
}
let prev = document.getElementsByClassName("arrow left")[0];
let next = document.getElementsByClassName("arrow right")[0];
prev.addEventListener("click", function() {
let slides = document.getElementsByClassName("slideshow")[0].getElementsByTagName("img");
slides[slideIndex-1].classList.remove("active");
slideIndex--;
if (slideIndex < 1) {
slideIndex = slides.length;
}
slides[slideIndex-1].classList.add("active");
});
next.addEventListener("click", function() {
let slides = document.getElementsByClassName("slideshow")[0].getElementsByTagName("img");
slides[slideIndex-1].classList.remove("active");
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1;
}
slides[slideIndex-1].classList.add("active");
});
</script>
</body>
</html>
```
你可以直接复制粘贴到HTML文件中运行查看效果。
阅读全文