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

小程序 0
.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;}

在这里插入图片描述

也许您对下面的内容还感兴趣: