Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

html做一个登录注册页面

作者:寂寞带点伤   发布日期:2026-04-19   浏览:39

<!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>

解释说明

  1. HTML结构:

    • 页面包含两个表单:一个用于登录 (loginForm),另一个用于注册 (registerForm)。
    • 使用了两个按钮来切换显示不同的表单。
  2. CSS样式:

    • 设置了页面的整体布局和样式,使页面居中显示,并为输入框和按钮添加了样式。
    • 使用 flex 布局使页面内容居中对齐。
  3. JavaScript逻辑:

    • 定义了两个函数 showLoginshowRegister 来控制表单的显示与隐藏。
    • 点击“登录”按钮时显示登录表单,点击“注册”按钮时显示注册表单。

上一篇:html标签作用

下一篇:html文本居中

大家都在看

静态html源码

404 html

ios打开html

用于定义html文档所要显示内容的是

nginx访问不到html

html 符号

colspan在html中是什么意思

html iframe嵌套页面

怎么将网页另存为html

xml转html

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站