响应式布局:登录界面

发布于:2024-12-06 ⋅ 阅读:(101) ⋅ 点赞:(0)
<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  <title>登录界面</title>
  <style>
    /* 全局样式 */
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    body {
      font-family: Arial, sans-serif;
      background-color: #f4f4f4;
      min-height: 90vh;
      max-height: 100vh;
    }

    .login-container {
      display: flex;
      justify-content: center;
      align-items: flex-start; /* 更改为 flex-start,让登录框靠上 */
      width: 100%;
      height: 100%;
    }

    .login-box {
      background-color: white;
      padding: 30px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
      border-radius: 8px;
      width: 100%;
      max-width: 400px;
      box-sizing: border-box;
      margin-top: 100px;
    }

    h2 {
      text-align: center;
      margin-bottom: 20px;
    }

    .input-group {
      margin-bottom: 20px;
    }

    .input-group label {
      display: block;
      font-size: 14px;
      color: #333;
      margin-bottom: 8px;
    }

    .input-group input {
      width: 100%;
      padding: 10px;
      font-size: 14px;
      border: 1px solid #ddd;
      border-radius: 4px;
      outline: none;
    }

    .input-group input:focus {
      border-color: #007bff;
    }

    .input-group button {
      width: 100%;
      padding: 10px;
      font-size: 16px;
      background-color: #007bff;
      color: white;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      transition: background-color 0.3s;
    }

    .input-group button:hover {
      background-color: #0056b3;
    }

    /* 响应式布局 */
    @media (max-width: 390px) {
      .login-box {
        padding: 20px;
        max-width: 90%;
      }

      h2 {
        font-size: 24px;
      }

      .input-group input,
      .input-group button {
        font-size: 16px;
        padding: 12px;
      }
    }

  </style>
</head>
<body>
  <div class="login-container">
    <div class="login-box">
      <h2>登录</h2>
      <form action="#">
        <div class="input-group">
          <label for="username">用户名</label>
          <input type="text" id="username" placeholder="请输入用户名" required>
        </div>
        <div class="input-group">
          <label for="password">密码</label>
          <input type="password" id="password" placeholder="请输入密码" required>
        </div>
        <div class="input-group">
          <button type="submit">登录</button>
        </div>
      </form>
    </div>
  </div>
</body>
</html>


网站公告

今日签到

点亮在社区的每一天
去签到