写一个个人中心页面包含导航栏、个人资料、头像等。并且为响应式布局
时间: 2023-06-20 09:05:01 浏览: 96
HTML代码:
```
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>个人中心</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav>
<div class="logo">
<a href="#">个人中心</a>
</div>
<ul class="nav-links">
<li><a href="#">首页</a></li>
<li><a href="#">个人资料</a></li>
<li><a href="#">我的订单</a></li>
<li><a href="#">退出</a></li>
</ul>
<div class="burger">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
<div class="container">
<div class="profile">
<div class="avatar">
<img src="avatar.png" alt="头像">
</div>
<div class="info">
<h1>用户名</h1>
<p>邮箱:xxx@xxx.com</p>
<p>电话:12345678901</p>
</div>
</div>
</div>
<script src="app.js"></script>
</body>
</html>
```
CSS代码:
```
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
nav {
display: flex;
justify-content: space-between;
align-items: center;
background-color: #333;
color: #fff;
padding: 1rem;
}
.logo a {
font-size: 1.5rem;
font-weight: bold;
text-decoration: none;
color: #fff;
}
.nav-links {
display: flex;
justify-content: space-around;
width: 40%;
list-style: none;
font-size: 1.2rem;
}
.nav-links li a {
text-decoration: none;
color: #fff;
}
.burger {
display: none;
cursor: pointer;
}
.burger div {
width: 25px;
height: 3px;
margin: 5px;
background-color: #fff;
}
.container {
max-width: 1200px;
margin: 2rem auto;
display: flex;
justify-content: center;
}
.profile {
display: flex;
align-items: center;
background-color: #f1f1f1;
padding: 1rem;
border-radius: 10px;
}
.avatar img {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
margin-right: 2rem;
}
.info h1 {
font-size: 2rem;
margin-bottom: 1rem;
}
@media screen and (max-width: 1024px) {
.nav-links {
width: 60%;
}
}
@media screen and (max-width: 768px) {
body {
overflow-x: hidden;
}
.nav-links {
position: absolute;
right: 0;
height: 92vh;
top: 8vh;
background-color: #333;
display: flex;
flex-direction: column;
align-items: center;
width: 60%;
transform: translateX(100%);
transition: transform 0.5s ease-in;
}
.nav-links li {
opacity: 0;
}
.burger {
display: block;
}
}
.nav-active {
transform: translateX(0%);
}
.line1 {
transform: rotate(45deg) translate(5px, 6px);
}
.line2 {
opacity: 0;
}
.line3 {
transform: rotate(-45deg) translate(5px, -6px);
}
```
JavaScript代码:
```
const navSlide = () => {
const burger = document.querySelector('.burger');
const nav = document.querySelector('.nav-links');
const navLinks = document.querySelectorAll('.nav-links li');
burger.addEventListener('click', () => {
nav.classList.toggle('nav-active');
navLinks.forEach((link, index) => {
if (link.style.animation) {
link.style.animation = '';
} else {
link.style.animation = `navLinkFade 0.5s ease forwards ${index / 7 + 0.3}s`;
}
});
burger.classList.toggle('toggle');
});
}
navSlide();
```
效果图:
![个人中心页面](https://img-blog.csdnimg.cn/20210728110544756.png)
阅读全文