Considering the following CSS/HTML block to build my screen layout, using flex, I need:
-
NAV BAR in the topmost
-
TITLE BAR in the topmost, under NAVBAR
-
COMMAND BAR in the very bottom
-
STATUS BAR in the bottom, above COMMAND BAR
-
Content: CHART and GAUGE in the middle, using all available height and width
Like:
|-----------------------------------|
| NAVBAR |
|-----------------------------------|
| TITLE BAR |
|-----------------------------------|
| |
| ↑ |
| <- CONTENT (CHART + GAUGE) -> |
| (fill remaining height and width) |
| ↓ |
| |
| |
| |
|-----------------------------------|
| STATUS BAR |
|-----------------------------------|
| COMMAND BAR |
|-----------------------------------|
.container {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
backgroud-color: grey;
}
.nav {
width: 100%;
height: auto;
background-color: yellow;
}
.title {
width: 100%;
height: auto;
background-color: orange
}
.content {
padding: 10px;
width: 100%;
height: auto;
overflow: hidden;
flex-grow: 1;
}
.status {
width: 100%;
height: auto;
background-color: orange
}
.footer {
width: 100%;
height: auto;
background-color: red;
}
.blocks {
display: flex;
flex-direction: row;
width: 100%;
height: 100%;
}
.chart {
padding: 10px;
display: flex;
flex: 4;
background-color: green;
}
.gauge {
padding: 10px;
display: flex;
flex: 2;
background-color: brown;
}
<div class="container">
<div class="nav">
NAV BAR
</div>
<div class="title">
TITLE BAR
</div>
<div class="content">
<div class="blocks">
<div class="chart">
CHART
</div>
<div class="gauge">
GAUGE
</div>
</div>
</div>
<div class="status">
STATUS BAR
</div>
<div class="footer">
COMMAND BAR
</div>
</div>
Unfortunatelly I’m having difficulties on flex behaviour… How can I fix it?
2
Answers
Not sure what this is what you’re after but you need to add height to the
html
andbody
element so the container can take that height, then I would make your content div flex so the blocks can grow to fill itYour code is correct. All you need to do is change the
height
property in the.container
to100vh
from100%
. The difference is that100%
will make the container as high as the content within it, while the100vh
will make the container fill the height of the viewport. I would also add some basic CSS resets such as removing all margins and paddings from thebody
and adding thebox-sizing: border-box
rule to all the elements (*
), to make sure that the width of the "boxes" are not stretched out when adding margins, paddings, and borders.