<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录注册页面</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f2f2f2;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 300px;
}
input[type="text"], input[type="password"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
.tab {
margin-bottom: 20px;
}
.tab button {
width: 48%;
}
</style>
</head>
<body>
<div class="container">
<div class="tab">
<button onclick="showLogin()">登录</button>
<button onclick="showRegister()">注册</button>
</div>
<form id="loginForm" style="display: block;">
<h2>登录</h2>
<input type="text" id="loginUsername" placeholder="用户名" required>
<input type="password" id="loginPassword" placeholder="密码" required>
<button type="submit">登录</button>
</form>
<form id="registerForm" style="display: none;">
<h2>注册</h2>
<input type="text" id="registerUsername" placeholder="用户名" required>
<input type="password" id="registerPassword" placeholder="密码" required>
<button type="submit">注册</button>
</form>
</div>
<script>
function showLogin() {
document.getElementById('loginForm').style.display = 'block';
document.getElementById('registerForm').style.display = 'none';
}
function showRegister() {
document.getElementById('loginForm').style.display = 'none';
document.getElementById('registerForm').style.display = 'block';
}
</script>
</body>
</html>
HTML结构:
loginForm),另一个用于注册 (registerForm)。CSS样式:
flex 布局使页面内容居中对齐。JavaScript逻辑:
showLogin 和 showRegister 来控制表单的显示与隐藏。上一篇:html标签作用
下一篇:html文本居中
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站