如何判断flexbox布局行占用浏览器窗口中剩余的垂直空间?

我有一个三排flexbox布局.前两行是固定高度的,但第三行是动态的,我希望它能扩展到浏览器的整个高度.

在此处输入图像描述

我在第3行有另一个FlexBox,它创建一组列.要正确调整这些列中的元素,我需要它们了解浏览器的完整高度--比如背景 colored颜色 和底部的项目对齐方式.主要布局最终将类似于以下内容:

在此处输入图像描述

.vwrapper {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    justify-content: flex-start;
    align-items: stretch;
    align-content: stretch;
    //height: 1000px;
}
.vwrapper #row1 {
    background-color: red;
}
.vwrapper #row2 {
    background-color: blue;
}
.vwrapper #row3 {
    background-color: green;
    flex 1 1 auto;
    display: flex;
}
.vwrapper #row3 #col1 {
    background-color: yellow;
    flex 0 0 240px;
}
.vwrapper #row3 #col2 {
    background-color: orange;
    flex 1 1;
}
.vwrapper #row3 #col3 {
    background-color: purple;
    flex 0 0 240px;
}
<body>
    <div class="vwrapper">
        <div id="row1">
            this is the header
        </div>
        <div id="row2">
            this is the second line
        </div>
        <div id="row3">
            <div id="col1">
                col1
            </div>
            <div id="col2">
                col2
            </div>
            <div id="col3">
                col3
            </div>
        </div>
    </div>
</body>

我try 添加height属性,当我将其设置为硬数字时,该属性确实起作用,但当我将其设置为100%时,则不起作用.我知道height: 100%不起作用,因为内容没有填满浏览器窗口,但是我可以使用FlexBox布局复制这个 idea 吗?

推荐答案

您应该将html, body, .wrapperheight设置为100%(以继承全高),然后仅将大于1flex值设置为.row3,而不对其他值进行设置.

.wrapper, html, body {
    height: 100%;
    margin: 0;
}
.wrapper {
    display: flex;
    flex-direction: column;
}
#row1 {
    background-color: red;
}
#row2 {
    background-color: blue;
}
#row3 {
    background-color: green;
    flex:2;
    display: flex;
}
#col1 {
    background-color: yellow;
    flex: 0 0 240px;
    min-height: 100%;/* chrome needed it a question time , not anymore */
}
#col2 {
    background-color: orange;
    flex: 1 1;
    min-height: 100%;/* chrome needed it a question time , not anymore */
}
#col3 {
    background-color: purple;
    flex: 0 0 240px;
    min-height: 100%;/* chrome needed it a question time , not anymore */
}
<div class="wrapper">
    <div id="row1">this is the header</div>
    <div id="row2">this is the second line</div>
    <div id="row3">
        <div id="col1">col1</div>
        <div id="col2">col2</div>
        <div id="col3">col3</div>
    </div>
</div>

100

Html相关问答推荐

隐藏滚动条和禁用文本 Select 的CSS技术?

删除第一个列表项上的左边框

如何使用css为动态用户输入矩阵添加背景色?

需要关于HTML的建议

如何创建嵌套的动态表单元素

如何将文本环绕心形(而不仅仅是圆形)?

rvest: Select 不包含链接的段落(<;p>;)

仅 Select 悬停的级别,而不 Select 其父级或子级

如何使用多边形制作如图所示的背景

Swift WKUserContentController 和 WKScriptMessageHandler 设置不正确

为什么溢出时overflow: auto框的底部有一个小间隙?

为什么我的图像在悬停时与固定顶部栏重叠?

当悬停时,同时影响相邻的两侧div

视频添加到 Html 与 Github 不同步

CSS 网格跨度行到所有行

如何使 Shiny 中的 selectInput Select 扩展到井面板之外或以其他方式使它们更容易被用户看到?

如何在滚动行中显示一张图片和下一张图片的一半?

提交前的验证表单未显示任何验证消息?

使元素扩展宽度减go margin-right