微信小程序头部、底部固定,中间滚动的布局

3,052 阅读1分钟

wxml

<view class='wraper'>
  <view class='header'>header</view>
  <view class='main'>
    <scroll-view class='main-scroll' scroll-y style="height: 100%">
      <view class='main-list'>
        <view class='card' wx:for="{{cardList}}">
          <view class='card-box'></view>
          <view>{{item.name}}</view>
          <view class='card-content'>{{item.content}}</view>
        </view>
      </view>
    </scroll-view>
  </view>
  <view class='footer'>footer</view>

wxss

page{
  width: 100%;
  height:100%;
}
 
.wraper{
  display: flex;
  flex-direction: column;
  width: 100%;
  height:100%;
}
 
.header{
  color: #fff;
  line-height: 100rpx;
  flex: 0 0 100rpx; /* 不放大不缩小固定100rpx */
}
 
.main{
  flex: 1;
  position: relative;
}
 
.main-scroll{
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
 
.main-list{
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
 
.footer{
  color: #fff;
  line-height: 100rpx;
  flex: 0 0 100rpx; /* 不放大不缩小固定100rpx */
}