【问题标题】:How to mange multiple divs' height and each div's height depends on another? [closed]如何管理多个 div 的高度,每个 div 的高度取决于另一个? [关闭]
【发布时间】:2019-09-19 17:06:07
【问题描述】:

https://stackblitz.com/edit/angular-z32zec,此时容器区域的高度是自适应屏幕高度的。标题区域总是在容器的顶部,它的高度是未知的。底部区域总是在容器的底部,但它的高度是一个常数。内容区域高度取决于页眉区域,因此如果三个区域的总高度小于屏幕高度,则可能会出现空白。当标题区域高度增加时,内容区域高度减小。比意味着底部区域高度和总高度永远不会改变。 我想知道是否有人知道如何实现这一目标?

【问题讨论】:

    标签: html css angular


    【解决方案1】:

    根据您的 stackblitz 演示,我认为这就是您想要的(如果不是,请告诉我):Stackbliz demo

    <div class="container">
    
        <div class="header">
            This header area height is unknown, maybe increase or decrease. asdfasd
        </div>
    
        <div class="content">
            This content area height depends on 'header area' height. It may have blank if the sum height of three areas is smaller than
            the screen height. When header area height increase, this area height decrease.
        </div>
    
        <div class="bottom-div">
            This area is always in the bottom of the container, and the container's height is the screen's height. The bottom area's
            height is a constant.
        </div>
    
    </div>
    
    
    .container {
      display: flex;
      flex-direction:column;
    
      &>* {
        flex-shrink: 0;
      }
    
      border: 1px solid red;
      height: 100vh;
    }
    
    
    .header {
      margin: 5px;
      border: 1px solid black;
    }
    
    .content {
      flex: 1;
      margin: 10px;
      border: 1px solid black;
    }
    
    .bottom-div {
      margin: 10px;
      border: 1px solid gray;
    }
    

    【讨论】:

    • 谢谢,但它有点不同。我想要的是:当标题高度增加时,内容高度减少,而不是向下移动。并且所有的空白都应该在内容区域。
    • 好的,很容易解决。再次查看 Stackbliz 演示(已更新)。
    • 谢谢,这正是我想要的。抱歉,我是 CSS 新手
    猜你喜欢
    • 2012-12-03
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多