html—登录及注册页面代码
时间: 2023-08-12 12:06:59 浏览: 92
登录和注册代码
4星 · 用户满意度95%
好的,以下是一个简单的登录及注册页面的HTML代码,你可以根据需要进行修改和完善:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录及注册页面</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f2f2f2;
}
.container {
margin: 50px auto;
width: 500px;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}
h1 {
text-align: center;
margin: 0 0 20px;
color: #333;
}
input[type="text"], input[type="password"], input[type="email"], input[type="tel"] {
width: 100%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}
input[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.cancelbtn {
width: auto;
padding: 10px 18px;
background-color: #f44336;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
.cancelbtn:hover {
background-color: #da190b;
}
.container .btn_group {
margin-bottom: 10px;
overflow: hidden;
}
.container .btn_group .btn {
float: left;
width: 50%;
padding: 10px;
text-align: center;
background-color: #f2f2f2;
color: #333;
border: none;
border-radius: 4px;
cursor: pointer;
}
.container .btn_group .btn.active {
background-color: #4CAF50;
color: #fff;
}
.alert {
padding: 20px;
background-color: #f44336;
color: #fff;
margin-bottom: 15px;
border-radius: 5px;
}
.closebtn {
margin-left: 15px;
color: #fff;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
.closebtn:hover {
color: #000;
}
@media screen and (max-width: 600px) {
.container {
width: 90%;
}
}
</style>
</head>
<body>
<div class="container">
<h1>登录及注册页面</h1>
<div id="login_form">
<form>
<label for="email"><b>邮箱</b></label>
<input type="email" placeholder="请输入邮箱" name="email" required>
<label for="psw"><b>密码</b></label>
<input type="password" placeholder="请输入密码" name="psw" required>
<button type="submit">登录</button>
</form>
</div>
<div id="register_form" style="display:none">
<form>
<label for="email"><b>邮箱</b></label>
<input type="email" placeholder="请输入邮箱" name="email" required>
<label for="tel"><b>手机号</b></label>
<input type="tel" placeholder="请输入手机号" name="tel" required>
<label for="username"><b>用户名</b></label>
<input type="text" placeholder="请输入用户名" name="username" required>
<label for="psw"><b>密码</b></label>
<input type="password" placeholder="请输入密码" name="psw" required>
<label for="psw-repeat"><b>确认密码</b></label>
<input type="password" placeholder="请再次输入密码" name="psw-repeat" required>
<button type="submit">注册</button>
</form>
</div>
<div class="btn_group">
<button class="btn active" onclick="showLoginForm()">登录</button>
<button class="btn" onclick="showRegisterForm()">注册</button>
</div>
</div>
<script>
// 显示登录表单
function showLoginForm() {
document.getElementById("login_form").style.display = "block";
document.getElementById("register_form").style.display = "none";
document.getElementsByClassName("btn")[0].classList.add("active");
document.getElementsByClassName("btn")[1].classList.remove("active");
}
// 显示注册表单
function showRegisterForm() {
document.getElementById("login_form").style.display = "none";
document.getElementById("register_form").style.display = "block";
document.getElementsByClassName("btn")[0].classList.remove("active");
document.getElementsByClassName("btn")[1].classList.add("active");
}
</script>
</body>
</html>
```
以上代码实现了一个简单的登录及注册页面,包括表单、按钮、响应式设计等。其中,使用了JavaScript来切换登录和注册表单,使页面更加友好。
阅读全文