css左右布局,左侧主要面板,右侧次要面板,通过改变右侧width宽度来实现隐藏时,如何不让右侧内容受到挤压?

作者站长头像
站长
· 阅读数 13

期望效果,右侧面板 width 慢慢减少至0,从而实现隐藏效果,但是不希望右侧内容在width减小过程中收到挤压,非常影响美观,改如何操作呢?

注:右侧结构内容比较复杂,所以最好不需要从内部结构入手,只需要修改右侧容最好。

vue 代码如下:

<template>
  <div class="about">
    <div class="lft">
      <button @click="() => isShowRight = !isShowRight">显示/隐藏</button>
    </div>
    <div class="rht" :class="!isShowRight ? 'closed' : ''">
      <div>隐藏右侧区块后,这些内容怎么不隐藏,还会受到挤压?</div>
    </div>
  </div>
</template>

<script>
export default {
  name: '',
  data() {
    return {
      isShowRight: true
    }
  },
  methods: {

  }
}
</script>

<style lang='css' scoped>
.about{
  height: 100%;
  width: 100%;
  display: flex;
}
.lft, .rht{
  height: 100%;
}
.lft{
  flex: 1;
  background: #e3e3e3;
}
.rht{
  transition: all 3s;
  width: 400px;
  background: rgb(201, 186, 186);
}
.closed{
  overflow: hidden;
  width: 0;
}
</style>

问题解决了:

搞定了,右侧三层div可以做到。

<div class="detail-area" :class="!isShowDetailPanel ? 'closed' : ''">
    <div class="detail-content">
        <div class="canvas-panel-wrapper">
                    

        </div>
    </div>
</div>
.detail-area{
  width: 350px;
  height: 100%;
  background: $bg-block;
  transition: all $delay;
  margin-left: 2px;
  box-sizing: border-box;
  display: flex;
  position: relative;
  &.closed{
    width: 0;
  }
  .detail-content{
    padding: 10px;
    box-sizing: border-box;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
  .canvas-panel-wrapper{
    flex: 1;
    flex-shrink: 0;
    overflow: hidden;
    position: absolute;
    width: 350px;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
  
}
回复
1个回答
avatar
test
2024-07-17

套一层 DIV,内部 white-space:nowrap外层改变宽度,不能压缩内层 div 就不会换行了

回复
likes
适合作为回答的
  • 经过验证的有效解决办法
  • 自己的经验指引,对解决问题有帮助
  • 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
  • 询问内容细节或回复楼层
  • 与题目无关的内容
  • “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容