我想创建一个登录和注册的页面,必须是自适应的
时间: 2024-03-19 14:43:41 浏览: 13
好的,以下是一个自适应的登录和注册页面 HTML/CSS 代码示例:
```html
<!DOCTYPE html>
<html>
<head>
<title>Login and Register</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
background-color: #f3f3f3;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.container {
width: 100%;
max-width: 600px;
margin: 0 auto;
padding: 20px;
box-sizing: border-box;
}
.form-container {
background-color: #fff;
padding: 20px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.3);
border-radius: 5px;
margin-bottom: 20px;
}
h1 {
text-align: center;
margin-bottom: 30px;
color: #333;
}
input[type="text"], input[type="password"], input[type="email"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
box-sizing: border-box;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.2s;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
.form-container p {
margin-bottom: 10px;
font-size: 14px;
color: #666;
}
.form-container a {
color: #4CAF50;
text-decoration: none;
}
.form-container a:hover {
text-decoration: underline;
}
.form-container .form-switch {
text-align: center;
}
.form-container .form-switch input {
display: none;
}
.form-container .form-switch label {
display: inline-block;
padding: 10px 20px;
margin-bottom: 0;
background-color: #eee;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.2s;
box-shadow: 0px 0px 10px rgba(0,0,0,0.1);
color: #666;
}
.form-container .form-switch label:hover {
background-color: #ddd;
}
.form-container .form-switch input:checked + label {
background-color: #4CAF50;
color: #fff;
}
</style>
</head>
<body>
<div class="container">
<h1>Login and Register</h1>
<div class="form-container">
<form id="login-form">
<p>Login to your account</p>
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Login">
<div class="form-switch">
<input type="checkbox" id="register-switch">
<label for="register-switch">Create a new account</label>
</div>
</form>
</div>
<div class="form-container" style="display:none;" id="register-form">
<form>
<p>Create a new account</p>
<input type="text" name="username" placeholder="Username">
<input type="email" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Register">
<div class="form-switch">
<input type="checkbox" id="login-switch">
<label for="login-switch">Already have an account</label>
</div>
</form>
</div>
</div>
<script>
const loginForm = document.getElementById('login-form');
const registerForm = document.getElementById('register-form');
const loginSwitch = document.getElementById('login-switch');
const registerSwitch = document.getElementById('register-switch');
loginSwitch.addEventListener('change', function() {
if (loginSwitch.checked) {
loginForm.style.display = 'none';
registerForm.style.display = 'block';
} else {
loginForm.style.display = 'block';
registerForm.style.display = 'none';
}
});
registerSwitch.addEventListener('change', function() {
if (registerSwitch.checked) {
loginForm.style.display = 'block';
registerForm.style.display = 'none';
} else {
loginForm.style.display = 'none';
registerForm.style.display = 'block';
}
});
</script>
</body>
</html>
```
这个示例页面包含一个登录表单和一个注册表单,通过切换两个表单之间的开关按钮,可以在登录和注册之间切换。整个页面使用了自适应的样式,可以在不同设备上自动调整布局和样式。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)