请帮我用html写一个好看的个人中心界面,要可以上传头像(头像显示在圆形框中),有名字,性别,年长,邮箱,座右铭以及关闭界面按钮
时间: 2023-04-07 14:02:41 浏览: 610
好的,以下是一个简单的个人中心界面的HTML代码,包括上传头像、名字、性别、年龄、邮箱、座右铭和关闭界面按钮:
```
<!DOCTYPE html>
<html>
<head>
<title>个人中心</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.container {
margin: 50px auto;
padding: 20px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
max-width: 500px;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
label {
display: block;
margin-bottom: 10px;
font-weight: bold;
}
input[type="text"], input[type="email"], input[type="password"] {
padding: 10px;
border-radius: 5px;
border: none;
margin-bottom: 20px;
width: 100%;
box-sizing: border-box;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-top: 20px;
}
.avatar {
width: 150px;
height: 150px;
border-radius: 50%;
background-color: #ccc;
background-size: cover;
background-position: center;
margin-bottom: 20px;
}
.file-input {
display: none;
}
.upload-btn {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-bottom: 20px;
}
.close-btn {
position: absolute;
top: 10px;
right: 10px;
background-color: #ccc;
color: #fff;
padding: 5px 10px;
border: none;
border-radius: 50%;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<h1>个人中心</h1>
<form>
<div class="avatar"></div>
<label for="avatar-upload" class="upload-btn">上传头像</label>
<input type="file" id="avatar-upload" class="file-input">
<label for="name">名字</label>
<input type="text" id="name" name="name" required>
<label for="gender">性别</label>
<select id="gender" name="gender" required>
<option value="">请选择</option>
<option value="male">男</option>
<option value="female">女</option>
</select>
<label for="age">年龄</label>
<input type="text" id="age" name="age" required>
<label for="email">邮箱</label>
<input type="email" id="email" name="email" required>
<label for="motto">座右铭</label>
<input type="text" id="motto" name="motto" required>
<input type="submit" value="保存">
<button type="button" class="close-btn">关闭</button>
</form>
</div>
<script>
// 上传头像
const avatarUpload = document.getElementById('avatar-upload');
const avatar = document.querySelector('.avatar');
avatarUpload.addEventListener('change', function() {
const file = this.files[0];
if (file) {
const reader = new FileReader();
reader.addEventListener('load', function() {
avatar.style.backgroundImage = `url(${this.result})`;
});
reader.readAsDataURL(file);
}
});
// 关闭界面
const closeBtn = document.querySelector('.close-btn');
closeBtn.addEventListener('click', function() {
window.close();
});
</script>
</body>
</html>
```