构建响应式网站知识点大全(三)

简介: 教程来源 https://ljtgc.cn/category/pc-games.html 本文介绍响应式网页开发三大核心:表格(水平滚动+卡片堆叠)、表单(单列/多列/水平布局及移动端优化)与布局模式(圣杯、瀑布流、响应式卡片网格),含完整CSS代码与适配技巧,助力构建全端兼容界面。

七、响应式表格

7.1 表格响应式策略

/* 策略1:水平滚动 */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table {
    min-width: 600px;
    width: 100%;
}

/* 策略2:堆叠卡片式 */
@media (max-width: 768px) {
    .stack-table,
    .stack-table thead,
    .stack-table tbody,
    .stack-table tr,
    .stack-table td,
    .stack-table th {
        display: block;
    }

    .stack-table thead {
        display: none;
    }

    .stack-table tr {
        border: 1px solid #ddd;
        margin-bottom: 1rem;
        border-radius: 8px;
        overflow: hidden;
    }

    .stack-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem;
        border-bottom: 1px solid #eee;
    }

    .stack-table td:before {
        content: attr(data-label);
        font-weight: bold;
        width: 40%;
    }

    .stack-table td:last-child {
        border-bottom: none;
    }
}

7.2 完整响应式表格示例

<style>
.table-wrapper {
    overflow-x: auto;
}

.responsive-table {
    width: 100%;
    border-collapse: collapse;
}

.responsive-table th,
.responsive-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

@media (max-width: 768px) {
    .responsive-table,
    .responsive-table thead,
    .responsive-table tbody,
    .responsive-table tr,
    .responsive-table th,
    .responsive-table td {
        display: block;
    }

    .responsive-table thead {
        display: none;
    }

    .responsive-table tr {
        margin-bottom: 1rem;
        border: 1px solid #ddd;
        border-radius: 8px;
    }

    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px;
        border-bottom: 1px solid #eee;
    }

    .responsive-table td:before {
        content: attr(data-label);
        font-weight: bold;
        margin-right: 1rem;
    }

    .responsive-table td:last-child {
        border-bottom: none;
    }
}
</style>

<div class="table-wrapper">
    <table class="responsive-table">
        <thead>
            <tr>
                <th>姓名</th>
                <th>职位</th>
                <th>部门</th>
                <th>工资</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td data-label="姓名">张三</td>
                <td data-label="职位">工程师</td>
                <td data-label="部门">技术部</td>
                <td data-label="工资">8000</td>
            </tr>
        </tbody>
    </table>
</div>

八、响应式表单

8.1 表单布局

/* 单列表单(移动端) */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

/* 多列表单(桌面端) */
@media (min-width: 768px) {
    .form-row {
        display: flex;
        gap: 1rem;
    }

    .form-row .form-group {
        flex: 1;
    }
}

/* 水平表单 */
@media (min-width: 768px) {
    .horizontal-form .form-group {
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .horizontal-form label {
        width: 120px;
        margin-bottom: 0;
        text-align: right;
    }

    .horizontal-form input,
    .horizontal-form select {
        flex: 1;
    }
}

8.2 移动端表单优化

/* 增大点击区域 */
input,
select,
button {
    min-height: 44px;  /* 移动端最小点击区域 */
}

/* 虚拟键盘优化 */
input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
}

/* 设置输入类型,优化键盘 */
<input type="email">      <!-- 邮箱键盘 -->
<input type="tel">        <!-- 数字键盘 -->
<input type="url">        <!-- URL键盘 -->
<input type="number">     <!-- 数字键盘 -->
<input type="search">     <!-- 搜索键盘 -->

/* 焦点状态优化 */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.25);
}

九、响应式布局模式

9.1 圣杯布局

<style>
.holy-grail {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.holy-grail header,
.holy-grail footer {
    background: #333;
    color: white;
    padding: 1rem;
}

.holy-grail .content {
    display: flex;
    flex: 1;
}

.holy-grail main {
    flex: 1;
    padding: 1rem;
}

.holy-grail .sidebar-left {
    width: 250px;
    padding: 1rem;
    background: #f5f5f5;
}

.holy-grail .sidebar-right {
    width: 250px;
    padding: 1rem;
    background: #f5f5f5;
}

@media (max-width: 768px) {
    .holy-grail .content {
        flex-direction: column;
    }

    .holy-grail .sidebar-left,
    .holy-grail .sidebar-right {
        width: auto;
    }
}
</style>

9.2 瀑布流布局

<style>
.masonry {
    column-count: 1;
    column-gap: 20px;
}

@media (min-width: 768px) {
    .masonry {
        column-count: 2;
    }
}

@media (min-width: 1200px) {
    .masonry {
        column-count: 3;
    }
}

.masonry-item {
    break-inside: avoid;
    margin-bottom: 20px;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.masonry-item img {
    width: 100%;
    height: auto;
    display: block;
}

.masonry-item .content {
    padding: 15px;
}
</style>

<div class="masonry">
    <div class="masonry-item">
        <img src="image1.jpg" alt="图片1">
        <div class="content">
            <h3>标题1</h3>
            <p>内容描述...</p>
        </div>
    </div>
    <!-- 更多卡片 -->
</div>

9.3 卡片式布局

/* 响应式卡片网格 */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    padding: 20px;
}

.card {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transition: transform 0.3s, box-shadow 0.3s;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.card-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.card-content {
    padding: 16px;
}

.card-title {
    font-size: 1.25rem;
    margin: 0 0 8px;
}

.card-text {
    color: #666;
    line-height: 1.5;
}

@media (max-width: 480px) {
    .card-grid {
        gap: 16px;
        padding: 12px;
    }

    .card-image {
        height: 160px;
    }
}

来源:
https://ljtgc.cn/category/pc-games.html

相关文章
|
9天前
|
人工智能 JSON 机器人
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
本文带你零成本玩转OpenClaw:学生认证白嫖6个月阿里云服务器,手把手配置飞书机器人、接入免费/高性价比AI模型(NVIDIA/通义),并打造微信公众号“全自动分身”——实时抓热榜、AI选题拆解、一键发布草稿,5分钟完成热点→文章全流程!
11102 95
让龙虾成为你的“公众号分身” | 阿里云服务器玩Openclaw
|
9天前
|
人工智能 IDE API
2026年国内 Codex 安装教程和使用教程:GPT-5.4 完整指南
Codex已进化为AI编程智能体,不仅能补全代码,更能理解项目、自动重构、执行任务。本文详解国内安装、GPT-5.4接入、cc-switch中转配置及实战开发流程,助你从零掌握“描述需求→AI实现”的新一代工程范式。(239字)
5213 132
|
5天前
|
人工智能 自然语言处理 供应链
【最新】阿里云ClawHub Skill扫描:3万个AI Agent技能中的安全度量
阿里云扫描3万+AI Skill,发现AI检测引擎可识别80%+威胁,远高于传统引擎。
1369 3
|
7天前
|
人工智能 并行计算 Linux
本地私有化AI助手搭建指南:Ollama+Qwen3.5-27B+OpenClaw阿里云/本地部署流程
本文提供的全流程方案,从Ollama安装、Qwen3.5-27B部署,到OpenClaw全平台安装与模型对接,再到RTX 4090专属优化,覆盖了搭建过程的每一个关键环节,所有代码命令可直接复制执行。使用过程中,建议优先使用本地模型保障隐私,按需切换云端模型补充功能,同时注重显卡温度与显存占用监控,确保系统稳定运行。
1794 5
|
15天前
|
人工智能 JavaScript API
解放双手!OpenClaw Agent Browser全攻略(阿里云+本地部署+免费API+网页自动化场景落地)
“让AI聊聊天、写代码不难,难的是让它自己打开网页、填表单、查数据”——2026年,无数OpenClaw用户被这个痛点困扰。参考文章直击核心:当AI只能“纸上谈兵”,无法实际操控浏览器,就永远成不了真正的“数字员工”。而Agent Browser技能的出现,彻底打破了这一壁垒——它给OpenClaw装上“上网的手和眼睛”,让AI能像真人一样打开网页、点击按钮、填写表单、提取数据,24小时不间断完成网页自动化任务。
2982 6

热门文章

最新文章