移动端或者小程序头部和底部固定,中介自适应滑动

https://www.jianshu.com/p/43273e398c66

<body>
  <div class="container">
    <header>2</header>
    <footer>1</footer>
  </div>
</body>

方法一

使用css 的计算属性 calc

 

.container{
   width: 100%;
   height: 100vh;
 }
 header{
   width: 100%;
   height: 50px;
   background: red;
 }
 footer{
   width: 100%;
   height: calc(100vh - 50px);
   background: blue;
 }

方法二

利用 css 弹性盒子 display:flex

flex布局详解

 

.container{
   width: 100%;
   height: 100vh;
   display: flex;
   flex-direction: column;
 }
 header{
   width: 100%;
   height: 50px;
   background: red;
   flex-grow: 0;
 }
 footer{
   width: 100%;
   background: blue;
   flex-grow: 1;
 }

小程序的 scroll-view 也可以用这种方法动态的去设置高度。需要稍微改动一下。
把 scroll-view 的高度设置成100%;给外出 body 一个高度。这个高度在flex-grow 的作用下并不会起作用。

 

<view class="container">
  <view class="header"></view>
  <view class="body">
     <scroll-view  :scroll-y="true" class="scroll-view"></scroll-view>
  </view>
</view>

 

.container{
   width: 100%;
   height: 100vh;
   display: flex;
   flex-direction: column;
 }
 .header{
   width: 100%;
   height: 50px;
   background: red;
   flex-grow: 0;
 }
.body{
   width: 100%;
   background: blue;
   heigth:100px;
   flex-grow: 1;
}
.scroll-view{
   height:100%;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值