用代码编一个有下拉列表的网站,要求有nav,背景图,footer
时间: 2024-03-16 10:45:24 浏览: 94
大图背景简洁的企业博客模板3262_html网站模板_网页源码移动端前端_H5模板_自适应响应式源码.rar
好的,以下是一个简单的用 HTML 和 CSS 编写的网站,包括了导航栏、背景图和底部页脚:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Website with Dropdown Menu</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Set background image */
body {
background-image: url('https://picsum.photos/1920/1080');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
/* Style navigation bar */
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
background-color: rgba(0,0,0,0.8);
padding: 10px 20px;
position: fixed;
top: 0;
left: 0;
right: 0;
}
.navbar-brand {
font-size: 24px;
font-weight: bold;
text-transform: uppercase;
color: #fff;
text-decoration: none;
}
.navbar-nav {
display: flex;
list-style: none;
margin: 0;
padding: 0;
}
.nav-item {
margin-left: 20px;
}
.nav-link {
font-size: 18px;
color: #fff;
text-decoration: none;
transition: all 0.3s ease;
}
.nav-link:hover {
color: #f00;
}
/* Style main content */
.main-content {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: calc(100vh - 80px);
}
.main-content h1 {
font-size: 48px;
font-weight: bold;
color: #fff;
margin-bottom: 20px;
}
.main-content p {
font-size: 24px;
color: #fff;
}
/* Style footer */
footer {
background-color: #333;
color: #fff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 20px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
footer p {
margin: 0;
font-size: 18px;
}
footer a {
color: #fff;
text-decoration: none;
transition: all 0.3s ease;
}
footer a:hover {
color: #f00;
}
</style>
</head>
<body>
<nav class="navbar">
<a class="navbar-brand" href="#">Website Name</a>
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link" href="#">Dropdown</a>
<ul class="dropdown-menu">
<li><a href="#">Link 1</a></li>
<li><a href="#">Link 2</a></li>
<li><a href="#">Link 3</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Page 1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Page 2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Page 3</a>
</li>
</ul>
</nav>
<div class="main-content">
<h1>Welcome to My Website</h1>
<p>Here you can find all the information you need!</p>
</div>
<footer>
<p>Contact Us:</p>
<p>123 Main St</p>
<p>Anytown, USA 12345</p>
<p>Phone: 555-555-5555</p>
<p>Email: info@website.com</p>
<p>Follow Us:</p>
<a href="#"><i class="fa fa-facebook"></i></a>
<a href="#"><i class="fa fa-twitter"></i></a>
<a href="#"><i class="fa fa-instagram"></i></a>
</footer>
</body>
</html>
```
你可以将上述代码保存为一个HTML文件并打开查看效果。注意,为了使下拉菜单正常工作,你需要使用JavaScript编写代码,或者使用现成的JavaScript库(如jQuery或Bootstrap)。
阅读全文