当前位置:  开发笔记 > 前端 > 正文

Flexbox的.避免高于父母的孩子(栏目方向)

如何解决《Flexbox的.避免高于父母的孩子(栏目方向)》经验,为你挑选了1个好方法。

我正在使用flexbox为一个站点搭建基本UI.与通常的电子邮件布局非常相似.

出于某种原因,第二个孩子(类.main-body,海藻绿柱,layouted Flexbox的容器的颜色)( .content-main,李子色)比其母公司,这一点我一个更大的高度希望它.

我制作了一个codepen代码段来显示这种行为.

html,
body {
  width: 100%;
  height: 100%;
  background: lightblue;
  box-sizing: border-box;
}
* {
  box-sizing: border-box;
}
.container {
  height: inherit;
  background: PeachPuff;
  padding: 1em;
  display: flex;
  max-height: 500px;
}
.sidebar {
  flex: 0 1 15%;
  background: khaki;
}
.content {
  flex: 1 1 auto;
  background: plum;
  padding: 0.8em;
  display: flex;
  flex-direction: column;
}
.content-header {
  background: lightgreen;
  padding: 0.3em;
  flex: 0 0 7%;
}
.content-main {
  display: flex;
  background: darkseagreen;
  padding: 1em;
  height: 100%;
  flex: 1 1 auto;
}
.main-list {
  flex: 0 0 12%;
  background: lightcoral;
}
.main-body {
  flex: 0 1 auto;
  padding: 1em;
  background: lightcyan;
  display: flex;
  flex-flow: row wrap;
  overflow-y: scroll;
}
This iscontent header
  • List 1
  • List 2
  • List 3
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1

如何防止绿色孩子的身高比梅子父母更大?我希望孩子只能滚动但不会比父母高.



1> Oriol..:

Flexbox引入auto了新的初始值min-height.它使弹性物品的长度与其内容一样高.

您可以撤消通过设置min-height0,旧的初始值:

.content-main {
  min-height: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background: lightblue;
  box-sizing: border-box;
}
* {
  box-sizing: border-box;
}
.container {
  height: inherit;
  background: PeachPuff;
  padding: 1em;
  display: flex;
  max-height: 500px;
}
.sidebar {
  flex: 0 1 15%;
  background: khaki;
}
.content {
  flex: 1 1 auto;
  background: plum;
  padding: 0.8em;
  display: flex;
  flex-direction: column;
}
.content-header {
  background: lightgreen;
  padding: 0.3em;
  flex: 0 0 7%;
}
.content-main {
  display: flex;
  background: darkseagreen;
  padding: 1em;
  height: 100%;
  flex: 1 1 auto;
  min-height: 0;
}
.main-list {
  flex: 0 0 12%;
  background: lightcoral;
}
.main-body {
  flex: 0 1 auto;
  padding: 1em;
  background: lightcyan;
  display: flex;
  flex-flow: row wrap;
  overflow-y: scroll;
}
This iscontent header
  • List 1
  • List 2
  • List 3
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
First Second Third Third Third Third
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
1 1 1 1 1 1
推荐阅读
TXCWB_523
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有