OpenClaw 小屏适配方案,这里提供完整的移动端适配解决方案

openclaw OpenClaw博客 1

视口配置

HTML 基础配置

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <!-- 关键视口设置 -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
    <!-- iOS 适配 -->
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no, email=no">
</head>

CSS 适配方案

REM 适配(推荐)

/* 基准字号设置 */
html {
    font-size: 16px; /* PC端基准 */
}
@media screen and (max-width: 768px) {
    html {
        font-size: 14px; /* 平板端基准 */
    }
}
@media screen and (max-width: 375px) {
    html {
        font-size: 12px; /* 手机端基准 */
    }
}
/* 使用 REM 单位 */
.container {
    padding: 1rem; /* 自适应 */
    margin: 0.5rem auto;
    max-width: 100%;
}
/* 固定像素转 REM 函数 */
:root {
    --font-size-base: 16px;
}
@function px2rem($px) {
    @return ($px / var(--font-size-base)) * 1rem;
}

VW/VH 适配

/* 使用视口单位 */
.container {
    width: 100vw;
    min-height: 100vh;
    padding: 5vw; /* 相对于视口宽度的 padding */
}
/* 字体大小使用 vw */
.text-large {
    font-size: 4vw; /* 视口宽度的 4% */
}
.text-medium {
    font-size: 3vw;
}
/* 在超小屏上限制最小字体 */
@media screen and (max-width: 320px) {
    .text-large {
        font-size: 12px;
    }
}

Flexbox 布局适配

/* 弹性容器 */
.flex-container {
    display: flex;
    flex-wrap: wrap; /* 允许换行 */
    justify-content: space-between;
    align-items: center;
    gap: 1rem; /* 间距 */
}
/* 响应式列布局 */
.responsive-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}
/* 在小屏上调整布局 */
@media (max-width: 768px) {
    .flex-container {
        flex-direction: column;
        gap: 0.5rem;
    }
    .responsive-grid {
        grid-template-columns: 1fr; /* 单列显示 */
    }
}

OpenClaw 组件适配

导航栏适配

.openclaw-nav {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
/* 移动端汉堡菜单 */
@media (max-width: 768px) {
    .openclaw-nav-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background: white;
        box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    }
    .nav-toggle {
        display: block;
    }
}

表格适配

/* 响应式表格 */
.openclaw-table {
    width: 100%;
    overflow-x: auto; /* 水平滚动 */
    -webkit-overflow-scrolling: touch; /* 平滑滚动 */
}
@media (max-width: 768px) {
    .openclaw-table {
        display: block;
    }
    .openclaw-table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #eee;
    }
    .openclaw-table td {
        display: block;
        text-align: right;
        position: relative;
        padding-left: 50%;
    }
    .openclaw-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 1rem;
        width: 45%;
        text-align: left;
        font-weight: bold;
    }
}

移动端交互优化

/* 触摸友好 */
.btn-mobile {
    min-height: 44px; /* iOS 建议的最小点击区域 */
    min-width: 44px;
    padding: 12px 20px;
    touch-action: manipulation; /* 禁用双击缩放 */
}
/* 防止点击闪烁 */
* {
    -webkit-tap-highlight-color: transparent;
}
/* 优化滚动 */
.scroll-area {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}
/* 输入框优化 */
input, textarea, select {
    font-size: 16px; /* 防止 iOS 缩放 */
    appearance: none;
    border-radius: 0; /* iOS 样式重置 */
}

断点配置

/* 定义断点 */
:root {
    --breakpoint-xs: 320px;  /* 小手机 */
    --breakpoint-sm: 375px;  /* 中手机 */
    --breakpoint-md: 768px;  /* 平板 */
    --breakpoint-lg: 1024px; /* 小桌面 */
    --breakpoint-xl: 1200px; /* 大桌面 */
}
/* 使用断点 */
@media (max-width: var(--breakpoint-md)) {
    .mobile-only {
        display: block;
    }
    .desktop-only {
        display: none;
    }
}
@media (min-width: var(--breakpoint-md)) {
    .mobile-only {
        display: none;
    }
    .desktop-only {
        display: block;
    }
}

完整示例组件

<div class="openclaw-responsive-card">
    <div class="card-header">
        <h3 class="card-title">响应式卡片</h3>
        <button class="card-action btn-mobile">操作</button>
    </div>
    <div class="card-content">
        <p>内容自适应各种屏幕尺寸</p>
    </div>
    <div class="card-footer">
        <button class="btn-mobile btn-primary">确认</button>
        <button class="btn-mobile btn-secondary">取消</button>
    </div>
</div>
.openclaw-responsive-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin: 1rem;
    padding: 1.5rem;
    transition: all 0.3s ease;
}
@media (max-width: 768px) {
    .openclaw-responsive-card {
        margin: 0.5rem;
        padding: 1rem;
        border-radius: 0;
    }
    .card-footer {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    .card-footer button {
        width: 100%;
    }
}

实用工具类

/* 响应式隐藏/显示 */
.hidden-xs { display: none; }
.visible-xs { display: block; }
@media (min-width: 375px) {
    .hidden-xs { display: block; }
    .visible-xs { display: none; }
}
/* 响应式间距 */
.spacing-xs { padding: 0.5rem; }
.spacing-sm { padding: 1rem; }
.spacing-md { padding: 1.5rem; }
.spacing-lg { padding: 2rem; }
@media (max-width: 768px) {
    .spacing-lg { padding: 1rem; }
    .spacing-md { padding: 0.75rem; }
}
/* 响应式字体 */
.text-responsive {
    font-size: clamp(14px, 3vw, 18px); /* 最小值 14px,视口宽度 3%,最大值 18px */
}

注意事项

  1. 测试设备覆盖:至少测试 iPhone SE、iPhone 12、iPad 等主流设备
  2. 横屏适配:考虑横屏时的布局变化
  3. 性能优化:移动端注意减少重绘和重排
  4. 网络状况:考虑弱网环境下的加载体验
  5. 手势操作:支持常见手势(滑动、捏合等)

检查清单

  • [ ] 视口 meta 标签已配置
  • [ ] 字体大小使用相对单位
  • [ ] 点击区域 ≥ 44×44px
  • [ ] 表单输入优化
  • [ ] 图片响应式(srcset)
  • [ ] 横向滚动支持
  • [ ] 键盘弹出处理
  • [ ] 安全区域适配(iPhone X+)

这个方案提供了完整的移动端适配策略,可根据具体项目需求进行调整。

OpenClaw 小屏适配方案,这里提供完整的移动端适配解决方案-第1张图片-OpenClaw 中文站-AI龙虾中文社区

标签: OpenClaw 小屏适配

抱歉,评论功能暂时关闭!