Skip to content
TheChatArchiveThe Chat Archive
o3-mini· OpenAIHugging Face LMArena Human Preference 140K

帮我写一个登录的网页

  1. User

    帮我写一个登录的网页

  2. Assistant

    下面给出一个简单的 HTML 登录页面示例,包括基本的 CSS 样式。你可以根据需要进一步扩展功能,比如加入服务端的验证或 Ajax 登录。

    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1">
      <title>登录页面</title>
      <style>
        /* 基本样式 */
        body {
          margin: 0;
          padding: 0;
          font-family: Arial, sans-serif;
          background-color: #f2f2f2;
        }
        .container {
          width: 300px;
          margin: 100px auto;
          padding: 20px;
          background-color: #fff;
          border-radius: 5px;
          box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        .container h2 {
          text-align: center;
          margin-bottom: 20px;
          color: #333;
        }
        .input-group {
          margin-bottom: 15px;
        }
        .input-group label {
          display: block;
          margin-bottom: 5px;
          color: #555;
        }
        .input-group input {
          width: 100%;
          padding: 8px 10px;
          box-sizing: border-box;
          border: 1px solid #ccc;
          border-radius: 4px;
          outline: none;
          transition: border-color 0.3s;
        }
        .input-group input:focus {
          border-color: #66afe9;
        }
        .btn-login {
          width: 100%;
          padding: 10px;
          border: none;
          border-radius: 4px;
          background-color: #007BFF;
          color: #fff;
          font-size: 16px;
          cursor: pointer;
          transition: background-color 0.3s;
        }
        .btn-login:hover {
          background-color: #0056b3;
        }
      </style>
    </head>
    <body>
      <div class="container">
        <h2>登录</h2>
        <form action="/login" method="post">
          <div class="input-group">
            <label for="username">用户名</label>
            <input type="text" id="username" name="username" placeholder="请输入用户名" required>
          </div>
          <div class="input-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password" placeholder="请输入密码" required>
          </div>
          <button type="submit" class="btn-login">登录</button>
        </form>
      </div>
    </body>
    </html>
    

    说明

    • HTML 部分

      • 页面使用 <form> 标签提交登录信息,action 属性中 /login 表示表单提交的地址,你可以根据服务器端接口进行修改。
      • method="post" 指定了表单数据以 POST 方式提交。
    • CSS 部分

      • 设置了基本的字体、背景及盒子样式,使页面看起来简单美观。
      • 输入框与按钮均采用了简洁的样式,并为焦点状态加入了过渡效果。

    你可以将以上代码保存为 .html 文件,然后在浏览器中打开进行测试。如果有进一步需求(例如前端验证、结合后端的登录逻辑等),可以再行扩展。