使用html、css、JavaScript设计登录注册页面
时间: 2023-10-24 18:07:59 浏览: 60
好的,我可以为你提供一个简单的登录注册页面的设计。
首先是 HTML 代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login/Register Page</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<div class="container">
<h1>Login/Register Page</h1>
<div class="form-container">
<form id="login-form">
<h2>Login</h2>
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
<form id="register-form">
<h2>Register</h2>
<label for="new-username">New Username:</label>
<input type="text" id="new-username" name="new-username" required>
<label for="new-password">New Password:</label>
<input type="password" id="new-password" name="new-password" required>
<label for="confirm-password">Confirm Password:</label>
<input type="password" id="confirm-password" name="confirm-password" required>
<button type="submit">Register</button>
</form>
</div>
</div>
</body>
</html>
```
接下来是 CSS 代码:
```css
body {
background-color: #f2f2f2;
font-family: Arial, sans-serif;
}
.container {
margin: 0 auto;
max-width: 500px;
padding: 20px;
text-align: center;
}
.form-container {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
margin-top: 20px;
}
form {
background-color: #fff;
border-radius: 8px;
box-shadow: 0px 2px 8px 0px rgba(0,0,0,0.1);
padding: 20px;
width: 45%;
}
h1 {
margin-bottom: 20px;
}
h2 {
margin-bottom: 10px;
}
label {
display: block;
margin-bottom: 5px;
text-align: left;
}
input[type="text"], input[type="password"] {
border: none;
border-radius: 4px;
box-shadow: 0px 2px 8px 0px rgba(0,0,0,0.1);
margin-bottom: 10px;
padding: 10px;
width: 100%;
}
button[type="submit"] {
background-color: #4CAF50;
border: none;
border-radius: 4px;
color: #fff;
cursor: pointer;
font-size: 16px;
margin-top: 10px;
padding: 10px;
width: 100%;
}
button[type="submit"]:hover {
background-color: #3e8e41;
}
@media (max-width: 768px) {
form {
width: 100%;
}
}
```
最后是 JavaScript 代码:
```javascript
const loginForm = document.getElementById("login-form");
const registerForm = document.getElementById("register-form");
loginForm.addEventListener("submit", (event) => {
event.preventDefault();
// TODO: 进行登录操作
});
registerForm.addEventListener("submit", (event) => {
event.preventDefault();
// TODO: 进行注册操作
});
```
这是一个简单的登录注册页面的设计,你可以根据需要进行修改和完善。