五、前端:解决表格table overflow: auto属性 固定表头,滚动表头以下内容@2019

本文分享了一种使用CSS技巧固定滚动表格头部的方法,通过调整样式属性实现表头在滚动时保持可见,适用于需要优雅展示大量数据的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

个人说明:个人用到了table 滚动overflow想要精致的方法固定表头,便实现并记录一下

<table id="table1" class="table table-striped table-bordered table-hover" style="margin: 0px;">
    <thead>
    <tr>
    <th class="center" style="width: 10%">序号1</th>
    <th class="center" style="width: 10%">序号2</th>
    <th class="center" style="width: 80%">序号3</th>
    </tr>
</table>
***重点**:主要是style="margin: 0px;"这个属性控制的*

1.镶嵌表的内容:

 <table id="table2" class="table table-striped table-bordered table-hover" >
    <tbody>
    <c:choose>
    <c:when test="${not empty list}">
    <c:forEach items="${userlist}" var="info" varStatus="vs">
    <tr>
    <td class='center'      style="width: 10.1%">1</td>
    <td class="center"     style="width: 10%">2</td>
    <td class="center"     style="width: 78%" >3</td>
    </tr>
    </c:forEach>
    </c:when>
    <c:otherwise>
    <tr class="main_info">
    <td colspan="13" class="center">没有相关数据</td>
    </tr>
    </c:otherwise>
    </c:choose>
    </tbody>
    </table>

2.镶嵌放在另外一个页面的内容:

<div id="tableMater" style="margin-top:-5px;max-height: 278px; overflow: auto; box-sizing: border-box;"><jsp:include page="table1.jsp"></jsp:include></div>

table1.jsp内容:

<table id="table2" class="table table-striped table-bordered table-hover" >
        <tbody>
        <c:choose>
        <c:when test="${not empty list}">
        <c:forEach items="${userlist}" var="info" varStatus="vs">
        <tr>
        <td class='center'      style="width: 10.1%">1</td>
        <td class="center"     style="width: 10%">2</td>
        <td class="center"     style="width: 78%" >3</td>
        </tr>
        </c:forEach>
        </c:when>
        <c:otherwise>
        <tr class="main_info">
        <td colspan="13" class="center">没有相关数据</td>
        </tr>
        </c:otherwise>
        </c:choose>
        </tbody>
        </table>

解决了自己的问题,我还只是个小白,文章仅供参考,如有不当,谢谢指教!!!谢谢
本人稍会一点java css js操作表单、表格,有兴趣可以一起讨论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值