响应式布局:登录界面

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>
相关推荐
晨光32115 小时前
Day34 模块与包的导入
java·前端·python
BD_Marathon5 小时前
Vue3_关于CSS样式的导入方式
前端·css
相闻秋歌5 小时前
六、背景相关属性
css·html5
苹果电脑的鑫鑫5 小时前
vue和react缩进规则的配置项如何配置
前端·vue.js·react.js
BD_Marathon5 小时前
Vue3_工程文件之间的关系
前端·javascript·vue.js
weibkreuz5 小时前
模块与组件、模块化与组件化的理解@3
开发语言·前端·javascript
拾忆,想起5 小时前
单例模式深度解析:如何确保一个类只有一个实例
前端·javascript·python·微服务·单例模式·性能优化·dubbo
RealizeInnerSelf丶5 小时前
Web 网页如何唤起本地 Windows 应用并传递参数(含 Electron 自动注册 + 手动配置指南)
前端·windows
IT_陈寒5 小时前
Redis 性能优化实战:5个被低估的配置项让我节省了40%内存成本
前端·人工智能·后端
chilavert3185 小时前
技术演进中的开发沉思-261 Ajax:动画优化
前端·javascript·ajax