【发布时间】:2019-05-08 22:28:51
【问题描述】:
我知道一个解决方案是将父元素设置为相对,将子元素设置为绝对。 任何人都可以使用更灵活的方式吗? (不要使用绝对)
请不要轻易将问题标记为重复Make flexbox children 100% height of their parent
因为我已经尝试过@David Storey 在该线程中提到的 flex 方式,看来我只能使其在 flex-direction: 行布局中工作,而它不能在我的小提琴中工作(flex-direction: column)布局。
HTML:
<div class="d-flex flex-column h-100">
<div class="p-2 d1">Flex item 1</div>
<div class="p-2 d6 flex-grow-1 d-flex position-relative">
<div class="inner h-100 flex-grow-1">
background-color: green;
</div>
</div>
</div>
CSS:
html,body{
height: 100%;
}
.d1 {
background-color: yellow;
}
.d6 {
background-color: green;
}
.inner {
background-color: red;
}
【问题讨论】:
-
您可以使用像素或垂直高度 (vh) 设置它。一定是百分比吗?
标签: html css flexbox bootstrap-4