我正在构建一个带有页眉/主要内容/页脚的组件,其中主要内容可以滚动。虽然我可以在 Js 中执行此操作,但我需要组件将高度和页脚的所有可用空间置于底部。即使代码正确,我也无法让它占据整个高度。
这是一支带有无效代码的笔:https ://codepen.io/SharpBCD/pen/MNgxgY
.panel {
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
flex-grow: 1;
justify-content: flex-start; /* align items in Main Axis */
align-items: stretch; /* align items in Cross Axis */
align-content: stretch; /* Extra space in Cross Axis */
background-color: #00acc1;
}
.panel-header{
flex: 0 1 auto;
/*max-height: fit-content;*/
}
.panel-main{
/*margin-bottom: auto;*/
display: flex;
flex-direction: column;
flex: 1; /* same as flex: 1 1 auto; */
justify-content: flex-start; /* align items in Main Axis */
align-items: stretch; /* align items in Cross Axis */
align-content: stretch; /* Extra space in Cross Axis */
background-color: #0d47a1;
}
.panel-footer{
margin-top: auto;
max-height: fit-content;
}
这是一个带有我尝试过的工作代码的 jsfiddle:https ://jsfiddle.net/MadLittleMods/LmYay/
.flexbox-parent
{
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: flex-start; /* align items in Main Axis */
align-items: stretch; /* align items in Cross Axis */
align-content: stretch; /* Extra space in Cross Axis */
background: rgba(255, 255, 255, .1);
}
.flexbox-item-grow
{
flex: 1; /* same as flex: 1 1 auto; */
}
.fill-area
{
display: flex;
flex-direction: row;
justify-content: flex-start; /* align items in Main Axis */
align-items: stretch; /* align items in Cross Axis */
align-content: stretch; /* Extra space in Cross Axis */
}
所以有什么问题?我做错了什么?