flex布局中的自动占满剩下的内容

70 篇文章 0 订阅
34 篇文章 0 订阅

没点击的时候

点击完后的样子:

代码:

<template>
  <div class="app">
    <div class="box" >
      <div class="box1"
           :style="{height : isTrue ? '200px':'auto'}"
           @click="clickButton"
      >
        box1
      </div>
      <div class="box2">box2</div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'app',
  data(){
      return {
          isTrue:true
      }
  },
  methods:{
    clickButton(){
        this.isTrue = ! this.isTrue
    }
  }
}
</script>

<style lang="less" scoped>
  .box{
    display: flex;
    width: 100%;
    /*height: 100%;*/
    height: 100vh;
    flex-direction: column;
    background-color: yellow;
    .box1{
      width: 100%;
      background-color:deeppink;
    }
    .box2{
      width: 100%;
      flex: auto;
      background-color: green;
    }
  }
</style>

做成这个需要有三个前提条件

1、父盒子(box)要设置 display: flex;  flex-direction: column;前两个固定的 height: 100vh;高度必须设置

2、子盒子1(box1)高度必须是根据条件判断必须包括一个定高,一个auto

3、子盒子2(box2)必须设置flex为auto

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值