设计一个的主页需要导航栏和页脚需要特效,背景图片是同目录的1.jpg文件
时间: 2024-03-24 22:39:46 浏览: 63
推荐一个不错的导航栏网页特效
好的,我可以通过以下 HTML 和 CSS 代码来设计这个带特效的主页:
```
<!DOCTYPE html>
<html>
<head>
<title>My Homepage</title>
<style>
body {
background-image: url('1.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
nav {
background-color: rgba(255, 255, 255, 0.7);
padding: 20px;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1;
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.3);
display: flex;
justify-content: space-between;
align-items: center;
height: 80px;
transition: all 0.5s ease-in-out;
}
nav.scrolled {
height: 60px;
background-color: rgba(255, 255, 255, 1);
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.5);
}
nav ul {
margin: 0;
padding: 0;
display: flex;
}
nav li {
list-style: none;
margin: 0 20px;
}
nav li a {
color: #333;
text-decoration: none;
font-size: 20px;
font-weight: bold;
transition: all 0.3s ease-in-out;
}
nav li a:hover {
color: #666;
}
main {
margin-top: 100px;
text-align: center;
transition: all 0.5s ease-in-out;
}
main h1 {
font-size: 50px;
font-weight: bold;
color: #fff;
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
transition: all 0.3s ease-in-out;
}
main p {
font-size: 24px;
color: #fff;
text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.5);
transition: all 0.3s ease-in-out;
}
footer {
background-color: rgba(255, 255, 255, 0.7);
padding: 20px;
position: fixed;
bottom: 0;
left: 0;
right: 0;
z-index: 1;
box-shadow: 0px -2px 5px rgba(0, 0, 0, 0.3);
transition: all 0.5s ease-in-out;
}
footer p {
margin: 0;
color: #333;
font-size: 16px;
text-align: center;
transition: all 0.3s ease-in-out;
}
@media screen and (max-width: 768px) {
nav {
height: auto;
padding: 10px;
}
nav li {
margin: 10px 0;
}
main {
margin-top: 80px;
}
main h1 {
font-size: 36px;
}
main p {
font-size: 20px;
}
footer {
padding: 10px;
}
footer p {
font-size: 14px;
}
}
</style>
</head>
<body>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
<div class="logo">My Homepage</div>
</nav>
<main>
<h1>Welcome to my homepage!</h1>
<p>Here you can learn more about me and my interests.</p>
</main>
<footer>
<p>© 2021 My Homepage. All rights reserved.</p>
</footer>
<script>
window.addEventListener('scroll', function() {
const nav = document.querySelector('nav');
const main = document.querySelector('main');
const footer = document.querySelector('footer');
const scrolled = window.pageYOffset > 0;
nav.classList.toggle('scrolled', scrolled);
main.style.marginTop = scrolled ? '60px' : '100px';
footer.style.bottom = scrolled ? '60px' : '0';
});
</script>
</body>
</html>
```
在这个代码中,我们使用了 `background-image` 属性来设置背景图片,并使用了 `background-size`、`background-position` 和 `background-repeat` 属性来对背景图片进行调整。然后,我们使用了 CSS 来对导航栏、主要内容和页脚进行样式调整,包括添加了透明度、阴影、过渡效果、悬停效果、响应式布局等。最后,我们使用 JavaScript 监听滚动事件,根据滚动距离来动态调整导航栏、主要内容和页脚的样式。
阅读全文