微信小程序实现简易table效果

.wxml
<view class="table-container">
  <scroll-view class="table-scroll" scroll-x>
    <view class="table-wrapper">
      <view class="header-wrapper">
        <view class="header">
        <text class="cell">1</text>
      <text class="cell">2</text>
      <text class="cell">3</text>
      <text class="cell">4</text>
      <text class="cell">5</text>
      <text class="cell">6</text>
      <text class="cell">7</text>
      <text class="cell">8</text>
      <text class="cell">9</text>
      <text class="cell">10</text>
      <text class="cell">11</text>
      </view>
      </view>
     
      <view class="content-wrapper">
      <scroll-view class="content" scroll-x scroll-y>
     
    <view class="row">
     <text class="cell">11</text>
      <text class="cell">12</text>
      <text class="cell">13</text>
      <text class="cell">14</text>
      <text class="cell">15</text>
      <text class="cell">16</text>
      <text class="cell">17</text>
      <text class="cell">18</text>
      <text class="cell">19</text>
      <text class="cell">110</text>
      <text class="cell">111</text>
    </view>
    <view class="row">
     <text class="cell">21</text>
      <text class="cell">22</text>
      <text class="cell">23</text>
      <text class="cell">24</text>
      <text class="cell">25</text>
      <text class="cell">26</text>
      <text class="cell">27</text>
      <text class="cell">28</text>
      <text class="cell">29</text>
      <text class="cell">210</text>
      <text class="cell">211</text>
    </view>
    <view class="row">
     <text class="cell">31</text>
      <text class="cell">32</text>
      <text class="cell">33</text>
      <text class="cell">34</text>
      <text class="cell">35</text>
      <text class="cell">36</text>
      <text class="cell">37</text>
      <text class="cell">38</text>
      <text class="cell">39</text>
      <text class="cell">310</text>
      <text class="cell">311</text>
    </view>
    <view class="row">
     <text class="cell">41</text>
      <text class="cell">42</text>
      <text class="cell">43</text>
      <text class="cell">44</text>
      <text class="cell">45</text>
      <text class="cell">46</text>
      <text class="cell">47</text>
      <text class="cell">48</text>
      <text class="cell">49</text>
      <text class="cell">410</text>
      <text class="cell">411</text>
    </view>
      </scroll-view>
    </view>
    </view>
  </scroll-view>
</view> 
.wxss
实现表格表头固定 表格内容随着表头可以滑动并且可以根据设定的内容高度300rpx实现滑动请求
.table-container {
  height: 400rpx; /* 表格容器高度 */
  overflow: hidden; /* 隐藏超出容器高度的内容 */
}

.table-scroll {
  width: 100%;
  height: 100%;
}

.table-wrapper {
  display: flex;
  flex-direction: column;
  /* 最小宽度是内容的最大适应宽度 */
  min-width: max-content;
}

.header-wrapper {
  position: sticky;
  top: 0;
  z-index: 1;
  background-color: #f5f5f5;
  border-bottom: 1rpx solid #ccc;
}

.header {
  display: flex;
}

.content {
  flex-grow: 1;
  height: 300rpx;
}

.row {
  display: flex;
  align-items: center;
  border-bottom: 1rpx solid #ccc;
}

.cell {
  flex: 1;
  padding: 10rpx;
  text-align: center;
}

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值