表格切割效果,“两个”表格实现列对应、变化一致

如何让两个表格的部分列对应且缩放一致

先看效果

使用一个原生table的即可实现

  1. "两个"表格的视觉效果
  2. 让"两个"表格的对应列缩放保持一致

废话不多说,直接上代码

html:

html 复制代码
<html>
    <div>
        <table>
            <caption class="table-name">表格1111111</caption>
            <tbody>
                <tr>
                    <th scope="col">序号</th>
                    <th scope="col">名称</th>
                    <th scope="col" style="width: 100px">单位</th>
                    <th scope="col">数量1</th>
                    <th scope="col">数量2</th>
                </tr>
                <tr>
                    <td>1</td>
                    <td>笔记本</td>
                    <td>本</td>
                    <td>100</td>
                    <td>200</td>
                </tr>
                <tr>
                    <td>2</td>
                    <td>笔</td>
                    <td>只</td>
                    <td>100</td>
                    <td>200</td>
                </tr>
            </tbody>
            <tfoot>
                <!-- 此行仅分割用 -->
                <tr style="display:block;height:20px"></tr>

                <tr>
                    <td class="none"></td>  <!--  占位 -->
                    <td class="none"></td>  <!--  占位 -->
                    <td class="none">编号</td>
                    <td>A</td>
                    <td>B</td>
                </tr>
                <tr>
                    <td class="none"></td>  <!--  占位 -->
                    <td class="none"></td>  <!--  占位 -->
                    <td class="none">铅封号</td>
                    <td>202410251555555555</td>
                    <td>202410251555555555</td>
                </tr>
            </tfoot>
        </table>
    </div>
</html>

css:

css 复制代码
table{
    margin-top: 20px;
    width: 100%;
    border-spacing: 0;
    color: #606266;

}
.table-name{
    text-align: left;
    font-size: 16px;
    margin-bottom: 8px;
    font-weight: 600;
}
th,td{
    text-align: center;
    border-bottom: 1px solid #eeeeee;
    border-left: 1px solid #eeeeee;
    padding: 4px 0;
}
th:last-child,td:last-child{
    border-right: 1px solid #eeeeee;
}
th{
    border-top: 1px solid #eeeeee;
    background: #f8faff;
}

tfoot tr:nth-child(2){
    td{
        border-top: 1px solid #eeeeee;
    }
}
.none{
    border: none !important;
}
闲话

这是开发中遇到的一个需求,原需求两个表格后面的列是动态的(可能有数量1、数量2、数量3...),下面个表格的列需要和上面的同步,所以想了这么个办法。

个人认为点睛之笔就是那个空白的tr。

相关推荐
t***5447 小时前
Clang 编译器在 Orwell Dev-C++ 中的局限性
开发语言·c++
LCG元7 小时前
STM32实战:基于STM32F103的Bootloader设计与IAP在线升级
javascript·stm32·嵌入式硬件
oy_mail7 小时前
QoS质量配置
开发语言·智能路由器·php
oyzz1207 小时前
PHP操作redis
开发语言·redis·php
nashane8 小时前
HarmonyOS 6学习:网络能力变化监听与智能提示——告别流量偷跑,打造贴心网络感知应用
开发语言·php·harmony app
凌波粒8 小时前
Java 8 “新”特性详解:Lambda、函数式接口、Stream、Optional 与方法引用
java·开发语言·idea
前端一小卒9 小时前
前端工程师的全栈焦虑,我用 60 天治好了
前端·javascript·后端
拾贰_C9 小时前
【Google | Gemini | API | POST】怎么使用Google 的Gemini API (原生版)
开发语言·lua
t***54410 小时前
如何在Dev-C++中选择Clang编译器
开发语言·c++