响应式布局:登录界面

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>
相关推荐
浩星3 分钟前
electron系列5:深入理解Electron打包
前端·javascript·electron
患得患失9497 分钟前
【前端WebSocket】心跳功能,心跳重置策略、双向确认(Ping-Pong) 以及 指数退避算法(Exponential Backoff)
前端·websocket·算法
英俊潇洒美少年9 分钟前
React 实现 AI 流式打字机对话:SSE 分包粘包处理 + 并发优化
前端·javascript·react.js
chQHk57BN12 分钟前
前端测试入门:Jest、Cypress等测试框架使用教程
前端
遇见你...21 分钟前
前端技术知识点
前端
AC赳赳老秦32 分钟前
OpenClaw image-processing技能实操:批量抠图、图片尺寸调整,适配办公需求
开发语言·前端·人工智能·python·深度学习·机器学习·openclaw
叫我一声阿雷吧37 分钟前
JS 入门通关手册(44):宏任务 / 微任务 / Event Loop(前端最难核心,面试必考
javascript·宏任务·event loop· 前端面试· 微任务· 事件循环·js单线程
We་ct39 分钟前
LeetCode 172. 阶乘后的零:从暴力到最优,拆解解题核心
开发语言·前端·javascript·算法·leetcode·typescript
军军君0139 分钟前
数字孪生监控大屏实战模板:可视化数字统计展示
前端·javascript·vue.js·typescript·echarts·数字孪生·前端大屏
此刻觐神1 小时前
IMX6ULL开发板学习-03(Linux文件相关命令)
前端·chrome