家明故事

自适应HTML页面设计与实现

家明 0 0

自适应HTML页面设计

我将为您创建两个自适应的HTML页面,它们都能在各种设备上良好显示。

页面一:带按钮的表格

html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据列表页面</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        
        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }
        
        header {
            display: flex;
            align-items: center;
            padding: 20px 0;
            border-bottom: 1px solid #eee;
            margin-bottom: 30px;
        }
        
        .logo {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 20px;
            color: white;
            font-weight: bold;
            font-size: 20px;
        }
        
        h1 {
            color: #2c3e50;
            font-size: 28px;
        }
        
        .table-container {
            overflow-x: auto;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        
        th, td {
            padding: 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        
        th {
            background-color: #f8f9fa;
            color: #6c757d;
            font-weight: 600;
            position: sticky;
            top: 0;
        }
        
        tr:hover {
            background-color: #f8f9fa;
        }
        
        .btn {
            padding: 8px 15px;
            background: #4e73df;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: background 0.3s;
        }
        
        .btn:hover {
            background: #2e59d9;
        }
        
        @media (max-width: 768px) {
            header {
                flex-direction: column;
                text-align: center;
            }
            
            .logo {
                margin-right: 0;
                margin-bottom: 15px;
            }
            
            th, td {
                padding: 10px 8px;
            }
            
            .btn {
                padding: 6px 10px;
                font-size: 12px;
            }
        }
        
        @media (max-width: 480px) {
            h1 {
                font-size: 22px;
            }
            
            th, td {
                padding: 8px 5px;
                font-size: 14px;
            }
            
            .btn {
                display: block;
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="logo">LOGO</div>
            <h1>数据管理面板</h1>
        </header>
        
        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>编号</th>
                        <th>标题</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>001</td>
                        <td>项目 Alpha 开发计划</td>
                        <td><button class="btn">查看详情</button></td>
                    </tr>
                    <tr>
                        <td>002</td>
                        <td>季度财务报告</td>
                        <td><button class="btn">查看详情</button></td>
                    </tr>
                    <tr>
                        <td>003</td>
                        <td>市场营销策略</td>
                        <td><button class="btn">查看详情</button></td>
                    </tr>
                    <tr>
                        <td>004</td>
                        <td>产品设计文档</td>
                        <td><button class="btn">查看详情</button></td>
                    </tr>
                    <tr>
                        <td>005</td>
                        <td>客户反馈分析</td>
                        <td><button class="btn">查看详情</button></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

页面二:简单表格

html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息表格页面</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        
        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background: white;
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
            padding: 20px;
        }
        
        header {
            display: flex;
            align-items: center;
            padding: 20px 0;
            border-bottom: 1px solid #eee;
            margin-bottom: 30px;
        }
        
        .logo {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #ff9a9e 0%, #fad0c4 100%);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 20px;
            color: #333;
            font-weight: bold;
            font-size: 20px;
        }
        
        h1 {
            color: #2c3e50;
            font-size: 28px;
        }
        
        .table-container {
            overflow-x: auto;
        }
        
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        
        th, td {
            padding: 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        
        th {
            background-color: #f8f9fa;
            color: #6c757d;
            font-weight: 600;
            position: sticky;
            top: 0;
        }
        
        tr:hover {
            background-color: #f8f9fa;
        }
        
        @media (max-width: 768px) {
            header {
                flex-direction: column;
                text-align: center;
            }
            
            .logo {
                margin-right: 0;
                margin-bottom: 15px;
            }
            
            th, td {
                padding: 10px 8px;
            }
        }
        
        @media (max-width: 480px) {
            h1 {
                font-size: 22px;
            }
            
            th, td {
                padding: 8px 5px;
                font-size: 14px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <div class="logo">LOGO</div>
            <h1>信息汇总表格</h1>
        </header>
        
        <div class="table-container">
            <table>
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>产品名称</th>
                        <th>类别</th>
                        <th>状态</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>P001</td>
                        <td>智能手表 Pro</td>
                        <td>可穿戴设备</td>
                        <td>可用</td>
                    </tr>
                    <tr>
                        <td>P002</td>
                        <td>无线耳机 Lite</td>
                        <td>音频设备</td>
                        <td>缺货</td>
                    </tr>
                    <tr>
                        <td>P003</td>
                        <td>便携式充电宝</td>
                        <td>配件</td>
                        <td>可用</td>
                    </tr>
                    <tr>
                        <td>P004</td>
                        <td>智能家居中心</td>
                        <td>家居自动化</td>
                        <td>预定</td>
                    </tr>
                    <tr>
                        <td>P005</td>
                        <td>蓝牙音箱</td>
                        <td>音频设备</td>
                        <td>可用</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

设计特点

  1. 响应式设计:两个页面都能自适应不同屏幕尺寸,在手机和平板上都能良好显示

  2. 现代UI设计:使用圆角、阴影和渐变效果,提供视觉吸引力

  3. 清晰的布局结构:包含logo、标题和表格,层次分明

  4. 交互元素:第一个页面包含可操作的按钮,第二个页面是纯信息展示

  5. 表格优化:表格在窄屏幕上会自动出现横向滚动,确保内容可访问性

您可以直接复制这些代码到HTML文件中,并在浏览器中打开查看效果。如果需要进一步调整样式或功能,可以修改CSS部分。

标签:HTML  

打赏

上一篇:AJAX请求PHP返回JSON数据示例

下一篇:没有了

发表评论