【问题标题】:Angular Material Nested Column Height Calculation角材料嵌套列高度计算
【发布时间】:2016-04-23 22:50:31
【问题描述】:

更新

似乎预期的行为发生在最新的 Firefox 和 Edge 中 - 这可能是 Chrome 独有的问题(不敢相信我输入了...)

Here 是一个说明问题的代码笔。这是代码:

HTML

<div class="thingone" layout="column" flex="100" layout-fill>
    <div class="thingtwo" layout="column" flex="75">
      <div class="thingfour" layout="column" flex="25"></div>
      <div class="thingfive" layout="column" flex="75"></div>
    </div>
    <div class="thingthree" layout="column" flex="25"></div>  
</div>

CSS

.thingone {
  background-color: red;
}
.thingtwo {
  background-color: blue;
  border: 10px solid black;
}
.thingthree {
  background-color: green;
  border: 10px solid white;
}
.thingfour {
  background-color: yellow;
}
.thingfive {
  background-color: orange;
}

我的最终目标是看到总共三个条形图 - 前两个条形图包裹在一个条形图中,占据父级可用区域的 75%,最后一个仅占用父级可用区域的 25%。前两个条形应分别占据其父级区域的 25% 和 75%。

正如您从 codepen 中看到的那样,我很接近,但子列不尊重他们 25% 和 75% 的弹性分配。作为一个简单的例子,我很难理解为什么。

理想情况下,我想要一个不涉及行的解决方案(因为此示例根据实际 UI 建模需要列),除非列嵌套在行中。

也许更重要的是 - 有什么简单的方法可以解释这里发生的事情?在处理 flex 中的嵌套列时是否必须应用“规则”(例如始终为父元素提供显式高度分配)?

谢谢!

【问题讨论】:

  • 当他们与某种建设性的评论配对时,反对票很好。我搜索了与此相关的其他问题,但没有发现任何直接相关的问题。有什么问题?

标签: html css flexbox angular-material


【解决方案1】:

解决问题的方法是在尝试让元素填充可用垂直空间时,不要在“thingtwo”元素上使用“layout-fill”属性。 'layout-fill' 指定了 min-height CSS 属性以及似乎导致布局问题的 height 属性。

对于那些偶然发现类似问题的人来说,以下是解决方案:

HTML

<div class="thingone" layout="column" flex="100">
    <div class="thingtwo" layout="column" flex="75">
      <div class="thingfour" layout="column" flex="25"></div>
      <div class="thingfive" layout="column" flex="75"></div>
    </div>
    <div class="thingthree" layout="column" flex="25"></div>  
</div>

CSS

.thingone {
  background-color: red;
  height: 100%;
}
.thingtwo {
  background-color: blue;
  border: 10px solid black;
  height: 100%;
}
.thingthree {
  background-color: green;
  border: 10px solid white;
}
.thingfour {
  background-color: yellow;
}
.thingfive {
  background-color: orange;
}

【讨论】:

  • 或者您可以手动设置flex: 1/3 CSS 并将height 排除在外,这可能是更好的跨浏览器:codepen.io/kuhnroyal/pen/dGZdYV
  • @kuhnroyal 感谢您的评论!我确实喜欢您的解决方案,但在这种情况下根本不使用材料的 flex 属性有点令人遗憾。鉴于 angular-material 已经过测试版,我希望能更多地依赖它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-16
  • 2019-02-28
  • 2015-10-16
  • 2015-07-28
  • 2018-08-02
  • 2022-01-18
  • 1970-01-01
相关资源
最近更新 更多