In the following situation, why is the height of <header>
reduced? As far as I can see, <header>
should retain the height declared in by flex-basis
and <div class="content-wrapper">
should take up the remaining space. This does work until it contains content that is taller than the space available to it. In this situation, <header>
partially collapses.
main {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
flex-direction: column;
}
header {
flex-basis: 50px;
background: red;
}
.content-wrapper {
background: blue;
flex: 2;
overflow-y: auto;
}
.content {
height: 1000px;
background: green;
}
<main>
<header></header>
<div class="content-wrapper">
<div class="content"></div>
</div>
</main>
If you run the snippet full-screen and change the height, the header height changes relative to the screen-height. I would expect it to remain fixed at 50px.
There is no difference between how flex-basis: will function on your element and how width: will function on your element. Width will even obey flex-shrink when using Flexbox.
Firstly, you can't apply a fixed width AND flex-grow. Secondly, flex-grow only works if the parent element has display:flex . In this case the section has display flex but the links do not and the flexgrow divs are children of the link…not the section.
The flex-basis property defines the size of the flex-item along the main axis of the flex container. The main axis is horizontal if flex-direction is set to row and it'll be vertical if the flex-direction property is set to column .
If you want to delete flex-basis , you can use width or height instead. When specified on a flex item, the auto keyword retrieves the value of the main size property as the used flex-basis . And the main size property is given by width (in row layouts) or height (in column layouts):
@Eric Martinez' comment is correct. To keep elements from shrinking, set flex-shrink
to 0 instead.
https://css-tricks.com/snippets/css/a-guide-to-flexbox/
main {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
display: flex;
flex-direction: column;
}
header {
height: 50px;
flex-shrink: 0;
background: red;
}
.content-wrapper {
background: blue;
flex: 2;
overflow-y: auto;
}
.content {
height: 1000px;
background: green;
}
<main>
<header></header>
<div class="content-wrapper">
<div class="content"></div>
</div>
</main>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With