【问题标题】:Flexbox 100% height within non-flexbox container非弹性盒容器内的弹性盒 100% 高度
【发布时间】:2016-07-05 14:46:22
【问题描述】:

考虑以下笔: http://codepen.io/anon/pen/xVgevE

我们的 flex 标记 <right-component> 位于第三方布局中,即高度不受限制的 div 中。

div 本身位于外部 flexbox 布局内。

如何在不硬编码或完全覆盖第三方组件的所有样式以使其由 flexbox 驱动的情况下使内部 flex 组件填充可用高度?

【问题讨论】:

    标签: html css flexbox


    【解决方案1】:

    您是否要让正确的内容填充空间。如果是这样,这个 jsFiddle 可能包含答案:https://jsfiddle.net/Dneilsen22/crfz66jx/

    您有一个高度设置为 100vh 的根,因此通过创建一个类似 rightComponent 的容器并将其设置为相同的高度,我们可以让内容填充 100% 的空间。

    CSS:

    #rightComponent {
      height: 100vh;
      display: flex;
      flex-direction: column;
    }
    
    #right-content {
      display:flex;
      flex-direction: column;
      background: #779;
      height:100%
    }
    

    HTML:

    <uncontrollable-third-party-component>
      <div>Third party stuff</div>
      <div id="rightComponent">
            <div id="right-topbar">
              Right topbar
            </div>
            <div id="right-content">
              Right content
            </div>
      </div>
    </uncontrollable-third-party-component>
    

    【讨论】:

    • right-component的高度不是100vh,是100vh减去上面第3方内容的未知高度
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-09
    • 2019-01-08
    • 2017-01-16
    • 2023-04-10
    • 2015-11-14
    • 2020-05-13
    • 1970-01-01
    相关资源
    最近更新 更多