代码之家  ›  专栏  ›  技术社区  ›  Frank N dqthe

渲染错误还是我的错误?:溢出隐藏零高度伸出FlexBox

  •  0
  • Frank N dqthe  · 技术社区  · 6 年前

    我想知道我是做错了什么,还是这是一个flex缺陷…(ubuntu下的当前chrome 65.03)

    <main>
    The outer container...
    <section class="collapsible">
        <button className='buttonA'>Click me</button>
    </section>
    </main>
    Some more text...
    

    enter image description here

    → Source (codepen)

    好: 虚线 main 是一个曲轴箱。

    .collapsible 是一个高度为零、顶部和底部有一条彩色线的元素(因此:这里显然没有边距折叠问题),显式 height: 0 overflow: hidden 是的。开发工具检查确认高度为零。

    仍然: 它的内部(一个按钮样式为 height:220px )显然有外部影响。一点也不接近它的周围 .可折叠的 但对梅恩来说…

    我觉得很奇怪。让我想起了经典的保证金崩盘痛(或结算浮动变得非常错误)。通过将main设置为 display: block 但我还是想知道为什么…

    1 回复  |  直到 6 年前
        1
  •  1
  •   Rob Monhemius    6 年前

    这与基线对齐有关。你设置 align-items: baseline main -选择器。它似乎对 align-items 财产。

    我没有时间阅读更多关于Flexbox Baselines ATM的内容,但我确信可以在这里找到更详细的解释: https://drafts.csswg.org/css-flexbox-1/#flex-baselines

    html {
      font-family: sans;
      font-size: 1.4em cosmetic;
    }
    
    main {
      border: 4px dashed rgba(255, 0, 0, 0.4);
      display: flex;
      flex-wrap: wrap;
      align-items: initial;
    }
    
    .collapsible {
      border-top: 2px solid blue;
      border-bottom: 2px solid purple;
      height: 0;
      width: 100%;
      overflow: hidden;
    }
    
    .collapsible-inner {
      background: rgba(128, 0, 128, 0.6);
    }
    
    button {
      height: 220px;
    }
    Flex elements appears to have a »radiation« affekt going beyond a height-0-element two levels up. Investigating...<br/>&nbsp;<br/>
    
    <main>
    The outer container...
    <section class="collapsible">
        <button className='buttonA'>Click me</button>  
    </section>
    </main>
    Some more text...