用html,css,js写一个有动态效果的用户登录注册页面
时间: 2023-03-04 16:04:50 浏览: 111
以下是一个简单的用户登录注册页面的HTML、CSS和JavaScript代码,具有动态效果:
```html
<!DOCTYPE html>
<html>
<head>
<title>User Login and Registration</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<div class="form-container">
<div class="form-btn">
<span>Login</span>
<span>Register</span>
<hr id="indicator">
</div>
<form id="login-form" method="post">
<input type="email" placeholder="Email" name="email" required>
<input type="password" placeholder="Password" name="password" required>
<button type="submit">Login</button>
</form>
<form id="register-form" method="post">
<input type="text" placeholder="Username" name="username" required>
<input type="email" placeholder="Email" name="email" required>
<input type="password" placeholder="Password" name="password" required>
<input type="password" placeholder="Confirm Password" name="confirm-password" required>
<button type="submit">Register</button>
</form>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
```
CSS样式:
```css
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: Arial, sans-serif;
}
body {
background-color: #f5f5f5;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.form-container {
background-color: #fff;
width: 400px;
padding: 40px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
}
.form-btn {
display: flex;
justify-content: space-between;
margin-bottom: 30px;
}
.form-btn span {
cursor: pointer;
padding: 10px;
width: 100%;
text-align: center;
font-size: 18px;
font-weight: bold;
color: #666;
}
.form-btn span:hover {
color: #333;
}
#indicator {
height: 2px;
background-color: #007bff;
margin-top: -10px;
transition: all 0.3s ease-in-out;
}
.form-btn span:first-child:hover ~ #indicator {
transform: translateX(0%);
}
.form-btn span:last-child:hover ~ #indicator {
transform: translateX(100%);
}
form input[type="text"],
form input[type="email"],
form input[type="password"],
form button[type="submit"] {
display: block;
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: none;
border-radius: 5px;
background-color: #f5f5f5;
font-size: 16px;
}
form button[type="submit"] {
background-color: #007bff;
color: #fff;
font-weight: bold;
}
form button[type="submit"]:hover {
background-color: #0069d9;
}
```
JavaScript代码:
```js
const loginForm = document.getElementById("login-form");
const registerForm = document.getElementById("register