响应式布局:登录界面

html 复制代码
<!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>
相关推荐
饼饼饼33 分钟前
React19 新手指南:JSX 没那么难,用好这几条规则就够了
前端·javascript·react.js
想吃火锅100533 分钟前
【前端手撕】new
前端
小小小小宇41 分钟前
AI大背景下端到端界面测试
前端
丷丩1 小时前
MapLibre GL JS第50课:用表达式创建虚线渐变线
javascript·gis·mapbox·maplibre gl js
小小小小宇1 小时前
前端端到端界面测试全解析与应用
前端
去伪存真1 小时前
如何将没有字幕的英文视频转换成中文视频?
前端·pytorch·llm
Coisinier1 小时前
RHCE中shell脚本基础(磁盘剩余空间监控,Web 服务状态检查,curl 访问 Web 服务并返回状态)
linux·运维·服务器·前端·nginx·操作系统
ywl4708120871 小时前
springSecurity+jwt,简单版demo
java·前端·servlet
想吃火锅10051 小时前
【前端手撕】promise.all
前端
lichenyang4531 小时前
动态加载 vs 延迟加载:为什么 demo 里「延迟」看起来没效果?
前端