登录和注册页面互换的代码(附css代码)
时间: 2023-03-23 09:01:56 浏览: 86
以下是一个基本的登录和注册页面互换的代码示例,包含HTML和CSS代码。它使用单个HTML文件,在切换时通过切换CSS类来切换登录和注册表单。
HTML代码:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login/Register Page</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="form-container">
<form class="login-form">
<h2>Login Form</h2>
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
<button type="submit">Login</button>
<p class="message">Not registered? <a href="#">Create an account</a></p>
</form>
<form class="register-form">
<h2>Register Form</h2>
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
<input type="email" placeholder="Email">
<button type="submit">Create Account</button>
<p class="message">Already registered? <a href="#">Login</a></p>
</form>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$('.message a').click(function(){
$('form').animate({height: "toggle", opacity: "toggle"}, "slow");
});
</script>
</body>
</html>
```
CSS代码:
```css
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
}
.form-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
form {
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
width: 400px;
}
h2 {
text-align: center;
}
input[type=text], input[type=password], input[type=email] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
border-radius: 4px;
}
button[type=submit] {
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
}
button[type=submit]:hover {
background-color: #45a049;
}
.message {
text-align: center;
}
.message a {
color: #4CAF50;
}
.login-form {
display: block;
}
.register-form {
display: none;
}
```
这个代码会在页面上显示一个包含登录表单和注册表单的容器。初始时,登录表单可见,注册表单隐藏。当用户单击"Create an account"链接时,使用jQuery的animate()函数来淡出登录表单并淡入注册表单。当用户单击"Login"链接时,执行相反的操作。CSS类 `.login-form` 和 `.register-form` 控制表单的可见性
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)