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

.wxml
cpp 复制代码
<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">行1列1</text>
      <text class="cell">行1列2</text>
      <text class="cell">行1列3</text>
      <text class="cell">行1列4</text>
      <text class="cell">行1列5</text>
      <text class="cell">行1列6</text>
      <text class="cell">行1列7</text>
      <text class="cell">行1列8</text>
      <text class="cell">行1列9</text>
      <text class="cell">行1列10</text>
      <text class="cell">行1列11</text>
    </view>
    <view class="row">
     <text class="cell">行2列1</text>
      <text class="cell">行2列2</text>
      <text class="cell">行2列3</text>
      <text class="cell">行2列4</text>
      <text class="cell">行2列5</text>
      <text class="cell">行2列6</text>
      <text class="cell">行2列7</text>
      <text class="cell">行2列8</text>
      <text class="cell">行2列9</text>
      <text class="cell">行2列10</text>
      <text class="cell">行2列11</text>
    </view>
    <view class="row">
     <text class="cell">行3列1</text>
      <text class="cell">行3列2</text>
      <text class="cell">行3列3</text>
      <text class="cell">行3列4</text>
      <text class="cell">行3列5</text>
      <text class="cell">行3列6</text>
      <text class="cell">行3列7</text>
      <text class="cell">行3列8</text>
      <text class="cell">行3列9</text>
      <text class="cell">行3列10</text>
      <text class="cell">行3列11</text>
    </view>
    <view class="row">
     <text class="cell">行4列1</text>
      <text class="cell">行4列2</text>
      <text class="cell">行4列3</text>
      <text class="cell">行4列4</text>
      <text class="cell">行4列5</text>
      <text class="cell">行4列6</text>
      <text class="cell">行4列7</text>
      <text class="cell">行4列8</text>
      <text class="cell">行4列9</text>
      <text class="cell">行4列10</text>
      <text class="cell">行4列11</text>
    </view>
      </scroll-view>
    </view>
    </view>
  </scroll-view>
</view> 
.wxss
实现表格表头固定 表格内容随着表头可以滑动并且可以根据设定的内容高度300rpx实现滑动请求
cpp 复制代码
.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;
}
相关推荐
说私域2 小时前
开源AI智能名片链动2+1模式S2B2C商城小程序源码赋能下的社交电商创业者技能跃迁与价值重构
人工智能·小程序·重构·开源·零售
中小企业实战军师刘孙亮12 小时前
实体店的小程序转型之路:拥抱新零售的密码-中小企实战运营和营销工作室博客
职场和发展·小程序·创业创新·学习方法·业界资讯·零售·内容运营
说私域13 小时前
基于开源技术体系的品牌赛道力重构:AI智能名片与S2B2C商城小程序源码驱动的品类创新机制研究
人工智能·小程序·重构·开源·零售
王哈哈的学习笔记15 小时前
uniapp小程序使用echarts
前端·小程序·uni-app
前端太佬18 小时前
小程序登录与授权功能全解析:从原理到设计的实战指南 (2025年最新规范实践版)
前端·微信·微信小程序
说私域19 小时前
颠覆传统微商!开源AI智能名片链动2+1模式S2B2C商城小程序:重构社交电商的“降维打击”革命
人工智能·小程序·开源·零售
ai大佬20 小时前
我是如何用AI编程制作一个AI表情包生成的小程序
人工智能·小程序·ai编程·api中转·apikey
2401_8906658621 小时前
免费送源码:Java+ssm+HTML 三分糖——甜品店网站设计与实现 计算机毕业设计原创定制
java·python·微信小程序·html·php·课程设计·android-studio
Maitians21 小时前
微信小程序 - 根据经纬度打开导航
微信小程序·小程序
前端太佬1 天前
微信小程序支付全流程实战指南(Node.js后端篇)
前端·javascript·微信小程序